hydrogen 1.2.3
Sampler.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23
24#ifndef SAMPLER_H
25#define SAMPLER_H
26
27#include <core/Object.h>
28#include <core/Globals.h>
30
31#include <inttypes.h>
32#include <vector>
33#include <memory>
34
35namespace H2Core
36{
37
38class Note;
39class Song;
40class Sample;
41class DrumkitComponent;
42class Instrument;
43struct SelectedLayerInfo;
44class InstrumentComponent;
45
49
50class Sampler : public H2Core::Object<Sampler>
51{
53public:
54
122
126 static const float K_NORM_DEFAULT;
127
128
129 // pan law functions
130 static float ratioStraightPolygonalPanLaw( float fPan );
131 static float ratioConstPowerPanLaw( float fPan );
132 static float ratioConstSumPanLaw( float fPan );
133 static float linearStraightPolygonalPanLaw( float fPan );
134 static float linearConstPowerPanLaw( float fPan );
135 static float linearConstSumPanLaw( float fPan );
136 static float polarStraightPolygonalPanLaw( float fPan );
137 static float polarConstPowerPanLaw( float fPan );
138 static float polarConstSumPanLaw( float fPan );
139 static float quadraticStraightPolygonalPanLaw( float fPan );
140 static float quadraticConstPowerPanLaw( float fPan );
141 static float quadraticConstSumPanLaw( float fPan );
142 // customly compensated
143 static float linearConstKNormPanLaw( float fPan, float k );
144 static float polarConstKNormPanLaw( float fPan, float k );
145 static float ratioConstKNormPanLaw( float fPan, float k );
146 static float quadraticConstKNormPanLaw( float fPan, float k );
147
160 static float getRatioPan( float fPan_L, float fPan_R );
161
162
165
172 Sampler();
173 ~Sampler();
174
175 void process( uint32_t nFrames );
176
180 bool isRenderingNotes() const;
181
183 void noteOn( Note * pNote );
184
186 void noteOff( Note *pNote );
187 void midiKeyboardNoteOff( int key );
188
189 void stopPlayingNotes( std::shared_ptr<Instrument> pInstr = nullptr );
190
192 return m_playingNotesQueue.size();
193 }
194
195 void preview_sample( std::shared_ptr<Sample> pSample, int length );
196 void preview_instrument( std::shared_ptr<Instrument> pInstr );
197
198 bool isInstrumentPlaying( std::shared_ptr<Instrument> pInstr );
199
203
204 std::shared_ptr<Instrument> getPreviewInstrument() const {
206 }
207
208 std::shared_ptr<Instrument> getPlaybackTrackInstrument() const {
210 }
211
213
223
236
237 const std::vector<Note*> getPlayingNotesQueue() const;
238
239private:
240 std::vector<Note*> m_playingNotesQueue;
241 std::vector<Note*> m_queuedNoteOffs;
242
244 std::shared_ptr<Instrument> m_pPlaybackTrackInstrument;
245
247 std::shared_ptr<Instrument> m_pPreviewInstrument;
248
255
257
260 float panLaw( float fPan, std::shared_ptr<Song> pSong );
261
262
263
264 bool processPlaybackTrack(int nBufferSize);
265
271 bool renderNote( Note* pNote, unsigned nBufferSize );
272
274
276 std::shared_ptr<Sample> pSample,
277 Note *pNote,
278 std::shared_ptr<SelectedLayerInfo> pSelectedLayerInfo,
279 std::shared_ptr<InstrumentComponent> pCompo,
280 std::shared_ptr<DrumkitComponent> pDrumCompo,
281 int nBufferSize,
282 int nInitialBufferPos,
283 float cost_L,
284 float cost_R,
285 float cost_track_L,
286 float cost_track_R,
287 float fLayerPitch
288 );
289};
290
291inline const std::vector<Note*> Sampler::getPlayingNotesQueue() const {
292 return m_playingNotesQueue;
293}
294
295} // namespace
296
297#endif
298
#define H2_OBJECT(name)
Definition Object.h:224
A note plays an associated instrument with a velocity left and right pan.
Definition Note.h:102
Waveform based sampler.
Definition Sampler.h:51
static float linearConstKNormPanLaw(float fPan, float k)
Definition Sampler.cpp:358
void process(uint32_t nFrames)
Definition Sampler.cpp:111
void noteOff(Note *pNote)
Stop playing a note.
Definition Sampler.cpp:241
static const float K_NORM_DEFAULT
default k for pan law with such that L^k + R^k = const must be initialised in Sampler....
Definition Sampler.h:126
static float linearStraightPolygonalPanLaw(float fPan)
Definition Sampler.cpp:298
static float quadraticConstKNormPanLaw(float fPan, float k)
Definition Sampler.cpp:363
std::shared_ptr< Instrument > getPlaybackTrackInstrument() const
Definition Sampler.h:208
void preview_instrument(std::shared_ptr< Instrument > pInstr)
Definition Sampler.cpp:1398
void handleTimelineOrTempoChange()
Recalculates all note starts to make them valid again after a TempoMarker was added to or deleted fro...
Definition Sampler.cpp:426
static float linearConstPowerPanLaw(float fPan)
Definition Sampler.cpp:307
float * m_pMainOut_L
sampler main out (left channel)
Definition Sampler.h:163
static float ratioConstPowerPanLaw(float fPan)
Definition Sampler.cpp:280
bool processPlaybackTrack(int nBufferSize)
Definition Sampler.cpp:803
bool isRenderingNotes() const
Definition Sampler.cpp:186
float * m_pMainOut_R
sampler main out (right channel)
Definition Sampler.h:164
int m_nPlayBackSamplePosition
Definition Sampler.h:256
void reinitializePlaybackTrack()
Loading of the playback track.
Definition Sampler.cpp:1436
std::shared_ptr< Instrument > getPreviewInstrument() const
Definition Sampler.h:204
static float ratioStraightPolygonalPanLaw(float fPan)
Definition Sampler.cpp:271
bool renderNoteResample(std::shared_ptr< Sample > pSample, Note *pNote, std::shared_ptr< SelectedLayerInfo > pSelectedLayerInfo, std::shared_ptr< InstrumentComponent > pCompo, std::shared_ptr< DrumkitComponent > pDrumCompo, int nBufferSize, int nInitialBufferPos, float cost_L, float cost_R, float cost_track_L, float cost_track_R, float fLayerPitch)
Definition Sampler.cpp:993
static float quadraticConstSumPanLaw(float fPan)
Definition Sampler.cpp:353
static float ratioConstSumPanLaw(float fPan)
Definition Sampler.cpp:289
std::vector< Note * > m_queuedNoteOffs
Definition Sampler.h:241
std::shared_ptr< Instrument > m_pPlaybackTrackInstrument
Instrument used for the playback track feature.
Definition Sampler.h:244
static float polarConstPowerPanLaw(float fPan)
Definition Sampler.cpp:327
static float quadraticConstPowerPanLaw(float fPan)
Definition Sampler.cpp:348
float panLaw(float fPan, std::shared_ptr< Song > pSong)
function to direct the computation to the selected pan law function
Definition Sampler.cpp:385
int m_nMaxLayers
Maximum number of layers to be used in the Instrument editor.
Definition Sampler.h:254
static float ratioConstKNormPanLaw(float fPan, float k)
Definition Sampler.cpp:375
void noteOn(Note *pNote)
Start playing a note.
Definition Sampler.cpp:190
void midiKeyboardNoteOff(int key)
Definition Sampler.cpp:229
bool renderNote(Note *pNote, unsigned nBufferSize)
Render a note.
Definition Sampler.cpp:517
std::vector< Note * > m_playingNotesQueue
Definition Sampler.h:240
Interpolation::InterpolateMode getInterpolateMode()
Definition Sampler.h:212
void stopPlayingNotes(std::shared_ptr< Instrument > pInstr=nullptr)
Definition Sampler.cpp:1341
static float quadraticStraightPolygonalPanLaw(float fPan)
Definition Sampler.cpp:339
Interpolation::InterpolateMode m_interpolateMode
Definition Sampler.h:273
static float linearConstSumPanLaw(float fPan)
Definition Sampler.cpp:312
static float polarConstKNormPanLaw(float fPan, float k)
Definition Sampler.cpp:368
const std::vector< Note * > getPlayingNotesQueue() const
Definition Sampler.h:291
void handleSongSizeChange()
Recalculates all note starts and positions to make them valid again after the song size changed,...
Definition Sampler.cpp:487
PAN_LAW_TYPES
PAN LAWS The following pan law functions return pan_L (==L, which is the gain for Left channel).
Definition Sampler.h:104
@ QUADRATIC_CONST_K_NORM
Definition Sampler.h:120
@ LINEAR_STRAIGHT_POLYGONAL
Definition Sampler.h:108
@ RATIO_STRAIGHT_POLYGONAL
Definition Sampler.h:105
@ POLAR_STRAIGHT_POLYGONAL
Definition Sampler.h:111
@ QUADRATIC_CONST_POWER
Definition Sampler.h:115
@ QUADRATIC_STRAIGHT_POLYGONAL
Definition Sampler.h:114
bool isInstrumentPlaying(std::shared_ptr< Instrument > pInstr)
Definition Sampler.cpp:1424
void setInterpolateMode(Interpolation::InterpolateMode mode)
Definition Sampler.h:200
Sampler()
Constructor of the Sampler.
Definition Sampler.cpp:70
static float polarStraightPolygonalPanLaw(float fPan)
Definition Sampler.cpp:317
void preview_sample(std::shared_ptr< Sample > pSample, int length)
Preview, uses only the first layer.
Definition Sampler.cpp:1368
static float polarConstSumPanLaw(float fPan)
Definition Sampler.cpp:333
static float getRatioPan(float fPan_L, float fPan_R)
This function is used to load old version files (v<=1.1).
Definition Sampler.cpp:257
std::shared_ptr< Instrument > m_pPreviewInstrument
Instrument used for the preview feature.
Definition Sampler.h:247
int getPlayingNotesNumber()
Definition Sampler.h:191