hydrogen 1.1.1
Sample Class Reference

#include <Sample.h>

Inheritance diagram for Sample:
Object

Data Structures

class  Loops
 set of loop configuration flags More...
 
class  Rubberband
 set of rubberband configuration flags More...
 

Public Types

using PanEnvelope = std::vector< std::unique_ptr< EnvelopePoint > >
 define the type used to store pan envelope points More...
 
using VelocityEnvelope = std::vector< std::unique_ptr< EnvelopePoint > >
 define the type used to store velocity envelope points More...
 

Public Member Functions

 Sample (const QString &filepath, int frames=0, int sample_rate=0, float *data_l=nullptr, float *data_r=nullptr)
 Sample constructor. More...
 
 Sample (std::shared_ptr< Sample > other)
 copy constructor More...
 
 ~Sample ()
 destructor More...
 
bool write (const QString &path, int format=(SF_FORMAT_WAV|SF_FORMAT_PCM_16))
 write sample to a file More...
 
bool load ()
 Load the sample stored in __filepath into __data_l and __data_r. More...
 
void unload ()
 Flush the current content of the left and right channel and the current metadata. More...
 
void apply (const Loops &loops, const Rubberband &rubber, const VelocityEnvelope &velocity, const PanEnvelope &pan)
 Apply transformations to the sample data. More...
 
bool apply_loops (const Loops &lo)
 apply loop transformation to the sample More...
 
void apply_velocity (const VelocityEnvelope &v)
 apply velocity transformation to the sample More...
 
void apply_pan (const PanEnvelope &p)
 apply velocity transformation to the sample More...
 
void apply_rubberband (const Rubberband &rb)
 apply rubberband transformation to the sample More...
 
bool exec_rubberband_cli (const Rubberband &rb)
 call rubberband cli to modify the sample More...
 
bool is_empty () const
 
const QString get_filepath () const
 
const QString get_filename () const
 
void set_filename (const QString &filename)
 
void set_frames (int value)
 __frames setter More...
 
int get_frames () const
 
void set_sample_rate (const int sampleRate)
 
int get_sample_rate () const
 
double get_sample_duration () const
 
int get_size () const
 
float * get_data_l () const
 
float * get_data_r () const
 
void set_is_modified (bool value)
 __is_modified setter More...
 
bool get_is_modified () const
 
PanEnvelopeget_pan_envelope ()
 
VelocityEnvelopeget_velocity_envelope ()
 
Loops get_loops () const
 
Rubberband get_rubberband () const
 
QString get_loop_mode_string () const
 
QString toQString (const QString &sPrefix, bool bShort=true) const override
 Formatted string version for debugging purposes. More...
 
- Public Member Functions inherited from Object
 ~Object ()
 destructor More...
 
 Object (const Object &obj)
 copy constructor More...
 
 Object (const char *class_name)
 constructor More...
 
const char * class_name () const
 return the class name More...
 
virtual QString toQString (const QString &sPrefix, bool bShort=true) const
 Formatted string version for debugging purposes. More...
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG. More...
 

Static Public Member Functions

static std::shared_ptr< Sampleload (const QString &filepath)
 Load a sample from a file. More...
 
static std::shared_ptr< Sampleload (const QString &filepath, const Loops &loops, const Rubberband &rubber, const VelocityEnvelope &velocity, const PanEnvelope &pan)
 
static Loops::LoopMode parse_loop_mode (const QString &string)
 parse the given string and rturn the corresponding loop_mode More...
 
- Static Public Member Functions inherited from Object
static void set_count (bool flag)
 enable/disable class instances counting More...
 
static bool count_active ()
 return true if class instances counting is enabled More...
 
static unsigned objects_count ()
 return the number of objects More...
 
static void write_objects_map_to (std::ostream &out)
 output the full objects map to a given ostream More...
 
static void write_objects_map_to_cerr ()
 output objects map to stderr More...
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation ! More...
 
static Loggerlogger ()
 return the logger instance More...
 

Private Attributes

QString __filepath
 filepath of the sample More...
 
int __frames
 number of frames in this sample More...
 
int __sample_rate
 samplerate for this sample More...
 
float * __data_l
 left channel data More...
 
float * __data_r
 right channel data More...
 
bool __is_modified
 true if sample is modified More...
 
PanEnvelope __pan_envelope
 pan envelope vector More...
 
VelocityEnvelope __velocity_envelope
 velocity envelope vector More...
 
Loops __loops
 set of loop parameters More...
 
Rubberband __rubberband
 set of rubberband parameters More...
 

Static Private Attributes

static const std::vector< QString > __loop_modes = { "forward", "reverse", "pingpong" }
 loop modes string More...
 

Additional Inherited Members

- Static Public Attributes inherited from Object
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes. More...
 
- Static Protected Attributes inherited from Object
static Logger__logger = nullptr
 logger instance pointer More...
 

Member Typedef Documentation

◆ PanEnvelope

using PanEnvelope = std::vector<std::unique_ptr<EnvelopePoint> >

define the type used to store pan envelope points

◆ VelocityEnvelope

using VelocityEnvelope = std::vector<std::unique_ptr<EnvelopePoint> >

define the type used to store velocity envelope points

Constructor & Destructor Documentation

◆ Sample() [1/2]

Sample ( const QString &  filepath,
int  frames = 0,
int  sample_rate = 0,
float *  data_l = nullptr,
float *  data_r = nullptr 
)

Sample constructor.

Parameters
filepaththe path to the sample
framesthe number of frames per channel in the sample
sample_ratethe sample rate of the sample
data_lthe left channel array of data
data_rthe right channel array of data

◆ Sample() [2/2]

Sample ( std::shared_ptr< Sample other)

copy constructor

◆ ~Sample()

~Sample ( )

destructor

Member Function Documentation

◆ apply()

void apply ( const Loops loops,
const Rubberband rubber,
const VelocityEnvelope velocity,
const PanEnvelope pan 
)

Apply transformations to the sample data.

The function is a wrapper around a specific apply_* functions.

Parameters
loopsLoops transformation parameters handed over to apply_loops().
rubberRubber Band transformation parameters handed over to apply_rubberband() in case Hydrogen was compiled to use the Rubber Band library for audio time-stretching and pitch-shifting (H2CORE_HAVE_RUBBERBAND) or exec_rubberband_cli() if is wasn't.
velocityVelocity envelope points handed over to apply_velocity().
panPan envelope points handed over to apply_pan().

◆ apply_loops()

bool apply_loops ( const Loops lo)

apply loop transformation to the sample

Parameters
loloops parameters

◆ apply_pan()

void apply_pan ( const PanEnvelope p)

apply velocity transformation to the sample

Parameters
pthe pan vector

◆ apply_rubberband()

void apply_rubberband ( const Rubberband rb)

apply rubberband transformation to the sample

Parameters
rbrubberband parameters

◆ apply_velocity()

void apply_velocity ( const VelocityEnvelope v)

apply velocity transformation to the sample

Parameters
vthe velocity vector

◆ exec_rubberband_cli()

bool exec_rubberband_cli ( const Rubberband rb)

call rubberband cli to modify the sample

Parameters
rbrubberband parameters

◆ get_data_l()

float * get_data_l ( ) const
inline
Returns
__data_l

◆ get_data_r()

float * get_data_r ( ) const
inline
Returns
__data_r

◆ get_filename()

const QString get_filename ( ) const
inline
Returns
Filename part of __filepath

◆ get_filepath()

const QString get_filepath ( ) const
inline
Returns
__filepath

◆ get_frames()

int get_frames ( ) const
inline
Returns
__frames accessor

◆ get_is_modified()

bool get_is_modified ( ) const
inline
Returns
__is_modified

◆ get_loop_mode_string()

QString get_loop_mode_string ( ) const
inline
Returns
mode member of __loops as a string

◆ get_loops()

Sample::Loops get_loops ( ) const
inline
Returns
__loops parameters

◆ get_pan_envelope()

Sample::PanEnvelope * get_pan_envelope ( )
inline

◆ get_rubberband()

Sample::Rubberband get_rubberband ( ) const
inline
Returns
__rubberband parameters

◆ get_sample_duration()

double get_sample_duration ( ) const
inline
Returns
sample duration in seconds

◆ get_sample_rate()

int get_sample_rate ( ) const
inline
Returns
__sample_rate

◆ get_size()

int get_size ( ) const
inline
Returns
data size, which is calculated by __frames time sizeof( float ) * 2

◆ get_velocity_envelope()

Sample::VelocityEnvelope * get_velocity_envelope ( )
inline

◆ is_empty()

bool is_empty ( ) const
inline
Returns
true if both data channels are null pointers

◆ load() [1/3]

load ( )

Load the sample stored in __filepath into __data_l and __data_r.

It uses libsndfile for reading both the content and the metadata of the sample file. The latter is stored in __frames and __sample_rate.

Hydrogen does only support up to SAMPLE_CHANNELS (two per default) channels in the audio file. If there are more, Hydrogen will NOT downmix its content but simply extract the first two channels and display a warning message. For mono file the same content will be assigned to both the left (__data_l) and right channel (__data_r).

If the total number of frames in the file is larger than the maximum value of an ‘int’, the content is truncated and a warning log message will be displayed.

◆ load() [2/3]

load ( const QString &  filepath)
static

Load a sample from a file.

This function checks whether the filepath is readable, initializes a new Sample, and calls the load() member on it.

Parameters
filepaththe file to load audio data from
Returns
Pointer to the newly initialized Sample. If the provided filepath is not readable, a nullptr is returned instead.

◆ load() [3/3]

load ( const QString &  filepath,
const Loops loops,
const Rubberband rubber,
const VelocityEnvelope velocity,
const PanEnvelope pan 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Wrapper around load(const QString& filepath), which calls apply() with loops, rubber, velocity, and pan as arguments after successfully loading the sample.

Parameters
filepaththe file to load audio data from
loopstransformation parameters
rubberband transformation parameters
velocityenvelope points
panenvelope points
Returns
Pointer to the newly initialized Sample. If the provided filepath is not readable, a nullptr is returned instead.

◆ parse_loop_mode()

Sample::Loops::LoopMode parse_loop_mode ( const QString &  string)
static

parse the given string and rturn the corresponding loop_mode

Parameters
stringthe loop mode text to be parsed

◆ set_filename()

void set_filename ( const QString &  filename)
Parameters
filenameFilename part of __filepath

◆ set_frames()

void set_frames ( int  value)

__frames setter

Parameters
valuethe new value for __frames

◆ set_is_modified()

void set_is_modified ( bool  value)
inline

__is_modified setter

Parameters
valuethe new value for __is_modified

◆ set_sample_rate()

void set_sample_rate ( const int  sampleRate)
inline
Parameters
sampleRateSets __sample_rate.

◆ toQString()

QString toQString ( const QString &  sPrefix,
bool  bShort = true 
) const
overridevirtual

Formatted string version for debugging purposes.

Parameters
sPrefixString prefix which will be added in front of every new line
bShortInstead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks.
Returns
String presentation of current object.

Reimplemented from Object.

◆ unload()

void unload ( )
inline

Flush the current content of the left and right channel and the current metadata.

◆ write()

bool write ( const QString &  path,
int  format = ( SF_FORMAT_WAV|SF_FORMAT_PCM_16 ) 
)

write sample to a file

Parameters
paththe path to write the sample to
formatthe format of the output

Field Documentation

◆ __data_l

float* __data_l
private

left channel data

◆ __data_r

float* __data_r
private

right channel data

◆ __filepath

QString __filepath
private

filepath of the sample

◆ __frames

int __frames
private

number of frames in this sample

◆ __is_modified

bool __is_modified
private

true if sample is modified

◆ __loop_modes

const std::vector< QString > __loop_modes = { "forward", "reverse", "pingpong" }
staticprivate

loop modes string

◆ __loops

Loops __loops
private

set of loop parameters

◆ __pan_envelope

PanEnvelope __pan_envelope
private

pan envelope vector

◆ __rubberband

Rubberband __rubberband
private

set of rubberband parameters

◆ __sample_rate

int __sample_rate
private

samplerate for this sample

◆ __velocity_envelope

VelocityEnvelope __velocity_envelope
private

velocity envelope vector