hydrogen 1.2.6
Sample Class Reference

#include <Sample.h>

Inheritance diagram for Sample:
Object< Sample > Base

Data Structures

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

Public Types

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

Public Member Functions

 Sample (const QString &filepath, const License &license=License(), int frames=0, int sample_rate=0, float *data_l=nullptr, float *data_r=nullptr)
 Sample constructor.
 
 Sample (std::shared_ptr< Sample > other)
 copy constructor
 
 ~Sample ()
 destructor
 
float * get_data_l () const
 
float * get_data_r () const
 
const QString get_filename () const
 
QString get_filepath () const
 
int get_frames () const
 
bool get_is_modified () const
 
QString get_loop_mode_string () const
 
Loops get_loops () const
 
PanEnvelopeget_pan_envelope ()
 
const QString get_raw_filepath () const
 
Rubberband get_rubberband () const
 
double get_sample_duration () const
 
int get_sample_rate () const
 
int get_size () const
 
VelocityEnvelopeget_velocity_envelope ()
 
License getLicense () const
 
bool is_empty () const
 
bool load (float fBpm=120)
 
void set_filename (const QString &filename)
 
void set_filepath (const QString &sFilepath)
 
void set_frames (int value)
 __frames setter
 
void set_is_modified (bool value)
 __is_modified setter
 
void set_loops (Loops loops)
 
void set_pan_envelope (PanEnvelope envelope)
 
void set_rubberband (Rubberband rubberband)
 
void set_sample_rate (const int sampleRate)
 
void set_velocity_envelope (VelocityEnvelope envelope)
 
void setLicense (const License &license)
 
QString toQString (const QString &sPrefix="", bool bShort=true) const override
 Formatted string version for debugging purposes.
 
void unload ()
 Flush the current content of the left and right channel and the current metadata.
 
bool write (const QString &path, int format=(SF_FORMAT_WAV|SF_FORMAT_PCM_16))
 write sample to a file
 
- Public Member Functions inherited from Object< Sample >
 Object ()
 
 Object (const Object< Sample > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void logBacktrace () const
 Print the current stack at point into the debug log.
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 

Static Public Member Functions

static std::shared_ptr< Sampleload (const QString &filepath, const License &license=License())
 
static Loops::LoopMode parse_loop_mode (const QString &string)
 parse the given string and rturn the corresponding loop_mode
 
static QString sndfileFormatToQString (int nFormat)
 
- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 

Private Member Functions

bool apply_loops ()
 apply __loops transformation to the sample
 
void apply_pan ()
 apply __pan_envelope transformation to the sample
 
void apply_rubberband (float fBpm)
 apply __rubberband transformation to the sample
 
void apply_velocity ()
 apply __velocity_envelope transformation to the sample
 
bool exec_rubberband_cli (float fBpm)
 call rubberband cli to modify the sample using __rubberband
 

Private Attributes

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

Static Private Attributes

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

Additional Inherited Members

- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from Object< Sample >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 
static bool bLogColors = true
 

Detailed Description

Definition at line 67 of file Sample.h.

Member Typedef Documentation

◆ PanEnvelope

using PanEnvelope = std::vector<EnvelopePoint>

define the type used to store pan envelope points

Definition at line 73 of file Sample.h.

◆ VelocityEnvelope

using VelocityEnvelope = std::vector<EnvelopePoint>

define the type used to store velocity envelope points

Definition at line 75 of file Sample.h.

Constructor & Destructor Documentation

◆ Sample() [1/2]

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

Sample constructor.

Parameters
filepaththe path to the sample
licenseassociated with 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

Definition at line 66 of file Sample.cpp.

◆ Sample() [2/2]

Sample ( std::shared_ptr< Sample > other)

copy constructor

Definition at line 80 of file Sample.cpp.

◆ ~Sample()

~Sample ( )

destructor

Definition at line 113 of file Sample.cpp.

Member Function Documentation

◆ apply_loops()

bool apply_loops ( )
private

apply __loops transformation to the sample

Definition at line 260 of file Sample.cpp.

◆ apply_pan()

void apply_pan ( )
private

apply __pan_envelope transformation to the sample

Parameters
pthe pan vector

Definition at line 394 of file Sample.cpp.

◆ apply_rubberband()

void apply_rubberband ( float fBpm)
private

apply __rubberband transformation to the sample

Parameters
fBpmtempo the Rubberband transformation will target

Definition at line 432 of file Sample.cpp.

◆ apply_velocity()

void apply_velocity ( )
private

apply __velocity_envelope transformation to the sample

Definition at line 363 of file Sample.cpp.

◆ exec_rubberband_cli()

bool exec_rubberband_cli ( float fBpm)
private

call rubberband cli to modify the sample using __rubberband

Parameters
fBpmtempo the Rubberband transformation will target

Definition at line 600 of file Sample.cpp.

◆ get_data_l()

float * get_data_l ( ) const
inline
Returns
__data_l

Definition at line 404 of file Sample.h.

◆ get_data_r()

float * get_data_r ( ) const
inline
Returns
__data_r

Definition at line 409 of file Sample.h.

◆ get_filename()

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

Definition at line 369 of file Sample.h.

◆ get_filepath()

QString get_filepath ( ) const

Definition at line 131 of file Sample.cpp.

◆ get_frames()

int get_frames ( ) const
inline
Returns
__frames accessor

Definition at line 379 of file Sample.h.

◆ get_is_modified()

bool get_is_modified ( ) const
inline
Returns
__is_modified

Definition at line 419 of file Sample.h.

◆ get_loop_mode_string()

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

Definition at line 424 of file Sample.h.

◆ get_loops()

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

Definition at line 439 of file Sample.h.

◆ get_pan_envelope()

Sample::PanEnvelope * get_pan_envelope ( )
inline
Returns
__pan_envelope

Definition at line 429 of file Sample.h.

◆ get_raw_filepath()

const QString get_raw_filepath ( ) const
inline
Returns
__filepath

Definition at line 359 of file Sample.h.

◆ get_rubberband()

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

Definition at line 444 of file Sample.h.

◆ get_sample_duration()

double get_sample_duration ( ) const
inline
Returns
sample duration in seconds

Definition at line 394 of file Sample.h.

◆ get_sample_rate()

int get_sample_rate ( ) const
inline
Returns
__sample_rate

Definition at line 384 of file Sample.h.

◆ get_size()

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

Definition at line 399 of file Sample.h.

◆ get_velocity_envelope()

Sample::VelocityEnvelope * get_velocity_envelope ( )
inline
Returns
__velocity_envelope

Definition at line 434 of file Sample.h.

◆ getLicense()

License getLicense ( ) const
inline

Definition at line 461 of file Sample.h.

◆ is_empty()

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

Definition at line 354 of file Sample.h.

◆ load() [1/2]

std::shared_ptr< Sample > load ( const QString & filepath,
const License & license = License() )
static

Definition at line 136 of file Sample.cpp.

◆ load() [2/2]

bool load ( float fBpm = 120)

Definition at line 156 of file Sample.cpp.

◆ 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

Definition at line 683 of file Sample.cpp.

◆ set_filename()

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

Definition at line 123 of file Sample.cpp.

◆ set_filepath()

void set_filepath ( const QString & sFilepath)
inline
Parameters
filenamesets __filepath

Definition at line 364 of file Sample.h.

◆ set_frames()

void set_frames ( int value)
inline

__frames setter

Parameters
valuethe new value for __frames

Definition at line 374 of file Sample.h.

◆ set_is_modified()

void set_is_modified ( bool value)
inline

__is_modified setter

Parameters
valuethe new value for __is_modified

Definition at line 414 of file Sample.h.

◆ set_loops()

void set_loops ( Loops loops)
inline

Definition at line 454 of file Sample.h.

◆ set_pan_envelope()

void set_pan_envelope ( PanEnvelope envelope)
inline

Definition at line 448 of file Sample.h.

◆ set_rubberband()

void set_rubberband ( Rubberband rubberband)
inline

Definition at line 457 of file Sample.h.

◆ set_sample_rate()

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

Definition at line 389 of file Sample.h.

◆ set_velocity_envelope()

void set_velocity_envelope ( VelocityEnvelope envelope)
inline

Definition at line 451 of file Sample.h.

◆ setLicense()

void setLicense ( const License & license)
inline

Definition at line 464 of file Sample.h.

◆ sndfileFormatToQString()

QString sndfileFormatToQString ( int nFormat)
static

Definition at line 836 of file Sample.cpp.

◆ 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 Base.

Definition at line 810 of file Sample.cpp.

◆ unload()

void unload ( )
inline

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

Definition at line 338 of file Sample.h.

◆ 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

Definition at line 696 of file Sample.cpp.

Field Documentation

◆ __data_l

float* __data_l
private

left channel data

Definition at line 311 of file Sample.h.

◆ __data_r

float* __data_r
private

right channel data

Definition at line 312 of file Sample.h.

◆ __filepath

QString __filepath
private

filepath of the sample

Definition at line 308 of file Sample.h.

◆ __frames

int __frames
private

number of frames in this sample

Definition at line 309 of file Sample.h.

◆ __is_modified

bool __is_modified
private

true if sample is modified

Definition at line 313 of file Sample.h.

◆ __loop_modes

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

loop modes string

Definition at line 319 of file Sample.h.

◆ __loops

Loops __loops
private

set of loop parameters

Definition at line 316 of file Sample.h.

◆ __pan_envelope

PanEnvelope __pan_envelope
private

pan envelope vector

Definition at line 314 of file Sample.h.

◆ __rubberband

Rubberband __rubberband
private

set of rubberband parameters

Definition at line 317 of file Sample.h.

◆ __sample_rate

int __sample_rate
private

samplerate for this sample

Definition at line 310 of file Sample.h.

◆ __velocity_envelope

VelocityEnvelope __velocity_envelope
private

velocity envelope vector

Definition at line 315 of file Sample.h.

◆ m_license

License m_license
private

Transient property indicating the license associated with the sample.

This variable is not stored on disk but either derived from the license of the drumkit containing the sample or specified by the user when loading the it directly.

It's value is only important for samples associated with a drumkit (stored in the InstrumentLayers of a kit). For "free" ones, like metronome or sound feedback when inserting notes in the Pattern Editor, it does not have to be specified.

Definition at line 333 of file Sample.h.