LMMS
Loading...
Searching...
No Matches
GigPlayer.h
Go to the documentation of this file.
1/*
2 * GigPlayer.h - a GIG player using libgig (based on Sf2 player plugin)
3 *
4 * Copyright (c) 2008 Paul Giblock <drfaygo/at/gmail/dot/com>
5 * Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 *
7 * This file is part of LMMS - https://lmms.io
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 */
25
26
27#ifndef GIG_PLAYER_H
28#define GIG_PLAYER_H
29
30#include <QList>
31#include <QMutex>
32#include <QMutexLocker>
33#include <samplerate.h>
34
35#include "AudioEngine.h"
36#include "AudioResampler.h"
37#include "Instrument.h"
38#include "PixmapButton.h"
39#include "InstrumentView.h"
40#include "Knob.h"
41#include "LcdSpinBox.h"
42#include "SampleFrame.h"
43#include "gig.h"
44
45
46class QLabel;
47
48
49namespace lmms
50{
51
52
53class NotePlayHandle;
54
55namespace gui
56{
57class PatchesDialog;
59}
60
61
62
63
65{
67} ;
68
69
70
71
72// Load a GIG file using libgig
74{
75public:
76 GigInstance( QString filename ) :
77 riff( filename.toUtf8().constData() ),
78 gig( &riff )
79 {}
80
81private:
82 RIFF::File riff;
83
84public:
85 gig::File gig;
86} ;
87
88
89
90
91// Stores options for the notes, e.g. velocity and release time
93{
95 release( false )
96 {
97 for( int i = 0; i < 8; ++i )
98 {
99 DimValues[i] = 0;
100 }
101 }
102
105} ;
106
107
108
109
110// Takes information from the GIG file for a certain note and provides the
111// amplitude (0-1) to multiply the signal by (internally incrementing the
112// position in the envelope when asking for the amplitude).
113class ADSR
114{
115 // From the file
116 float preattack; // initial amplitude (0-1)
117 float attack; // 0-60s
118 float decay1; // 0-60s
119 float decay2; // 0-60s
120 bool infiniteSustain; // i.e., no decay2
121 float sustain; // sustain amplitude (0-1)
122 float release; // 0-60s
123
124 // Used to calculate current amplitude
128 bool isDone;
134
135public:
136 ADSR();
137 ADSR( gig::DimensionRegion * region, int sampleRate );
138 void keyup(); // We will begin releasing starting now
139 bool done(); // Is this sample done playing?
140 float value(); // What's the current amplitude
141 void inc( f_cnt_t num ); // Increment internal positions by num
142} ;
143
144
145
146
147// The sample from the GIG file with our current position in both the sample
148// and the envelope
150{
151public:
152 GigSample(gig::Sample* pSample, gig::DimensionRegion* pDimRegion, float attenuation,
153 AudioResampler::Mode interpolation, float desiredFreq);
154 ~GigSample() = default;
155
156 // Needed when initially creating in QList
157 GigSample( const GigSample& g );
158 GigSample& operator=( const GigSample& g );
159
160 gig::Sample * sample;
161 gig::DimensionRegion * region;
164
165 // The position in sample
167
168 // Whether to change the pitch of the samples, e.g. if there's only one
169 // sample per octave and you want that sample pitch shifted for the rest of
170 // the notes in the octave, this will be true
172
173 // Used to convert sample rates
175 std::array<SampleFrame, DEFAULT_BUFFER_SIZE> m_sourceBuffer;
176 std::array<SampleFrame, DEFAULT_BUFFER_SIZE> m_mixBuffer;
177 std::span<SampleFrame> m_sourceBufferView;
178 std::span<SampleFrame> m_mixBufferView;
179
180 // Used changing the pitch of the note if desired
183} ;
184
185
186
187
188// What portion of a note are we in?
189enum class GigState
190{
191 // We just pressed the key
193 // The note is currently playing
195 // We just released the key
197 // The note is being released, e.g. a release sample is playing
199 // The note is done playing, you can delete this note now
201} ;
202
203
204
205
206// Corresponds to a certain midi note pressed, but may contain multiple samples
208{
209public:
212 bool release; // Whether to trigger a release sample on key up
213 bool isRelease; // Whether this is a release sample, changes when we delete it
216 std::vector<GigSample> samples;
217
218 // Used to determine which note should be released on key up
219 //
220 // Note: if accessing the data, be careful not to access it after the key
221 // has been released since that's when it is deleted
223
230} ;
231
232
233
234
236{
237 Q_OBJECT
238
239 mapPropertyFromModel( int, getBank, setBank, m_bankNum );
240 mapPropertyFromModel( int, getPatch, setPatch, m_patchNum );
241
242public:
243 GigInstrument( InstrumentTrack * _instrument_track );
244 ~GigInstrument() override;
245
246 void play( SampleFrame* _working_buffer ) override;
247
248 void playNote( NotePlayHandle * _n,
249 SampleFrame* _working_buffer ) override;
250 void deleteNotePluginData( NotePlayHandle * _n ) override;
251
252
253 void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
254 void loadSettings( const QDomElement & _this ) override;
255
256 void loadFile( const QString & _file ) override;
257
258 AutomatableModel * childModel( const QString & _modelName ) override;
259
260 QString nodeName() const override;
261
262 gui::PluginView* instantiateView( QWidget * _parent ) override;
263
264 QString getCurrentPatchName();
265
266
267 void setParameter( const QString & _param, const QString & _value );
268
269
270public slots:
271 void openFile( const QString & _gigFile, bool updateTrackName = true );
272 void updatePatch();
273 void updateSampleRate();
274
275
276private:
277 // The GIG file and instrument we're using
279 gig::Instrument * m_instrument;
280
281 // Part of the UI
282 QString m_filename;
283
286
288
289 // Locking for the data
292
293 // List of all the currently playing notes
294 QList<GigNote> m_notes;
295
296 // Used when determining which samples to use
299
300private:
301 // Delete the current GIG instance if one is open
302 void freeInstance();
303
304 // Open the instrument in the currently-open GIG file
305 void getInstrument();
306
307 // Create "dimension" to select desired samples from GIG file based on
308 // parameters such as velocity
309 Dimension getDimensions( gig::Region * pRegion, int velocity, bool release );
310
311 // Load sample data from the Gig file, looping the sample where needed
312 void loadSample( GigSample& sample, SampleFrame* sampleData, f_cnt_t samples );
313 f_cnt_t getLoopedIndex( f_cnt_t index, f_cnt_t startf, f_cnt_t endf ) const;
314 f_cnt_t getPingPongIndex( f_cnt_t index, f_cnt_t startf, f_cnt_t endf ) const;
315
316 // Add the desired samples to the note, either normal samples or release
317 // samples
318 void addSamples( GigNote & gignote, bool wantReleaseSample );
319
321
322signals:
326
327} ;
328
329
330namespace gui
331{
332
333
335{
336 Q_OBJECT
337public:
338 GigInstrumentView( Instrument * _instrument,
339 QWidget * _parent );
340 ~GigInstrumentView() override = default;
341
342private:
343 void modelChanged() override;
344
347
350
352 QLabel * m_patchLabel;
353
355
357
358protected slots:
359 void invalidateFile();
360 void showFileDialog();
361 void showPatchDialog();
362 void updateFilename();
363 void updatePatchName();
364} ;
365
366
367} // namespace gui
368
369} // namespace lmms
370
371#endif
unsigned int uint
Definition CarlaDefines.h:327
Definition GigPlayer.h:114
f_cnt_t attackPosition
Definition GigPlayer.h:129
float amplitude
Definition GigPlayer.h:125
f_cnt_t releasePosition
Definition GigPlayer.h:132
void inc(f_cnt_t num)
Definition GigPlayer.cpp:1264
float decay1
Definition GigPlayer.h:118
void keyup()
Definition GigPlayer.cpp:1186
bool isAttack
Definition GigPlayer.h:126
float sustain
Definition GigPlayer.h:121
f_cnt_t decayLength
Definition GigPlayer.h:131
bool done()
Definition GigPlayer.cpp:1195
bool infiniteSustain
Definition GigPlayer.h:120
float preattack
Definition GigPlayer.h:116
bool isDone
Definition GigPlayer.h:128
float release
Definition GigPlayer.h:122
ADSR()
Definition GigPlayer.cpp:1132
float value()
Definition GigPlayer.cpp:1204
f_cnt_t attackLength
Definition GigPlayer.h:130
bool isRelease
Definition GigPlayer.h:127
float decay2
Definition GigPlayer.h:119
float attack
Definition GigPlayer.h:117
f_cnt_t releaseLength
Definition GigPlayer.h:133
A utility class for resampling interleaved audio buffers using various resampling algorithms.
Definition AudioResampler.h:41
Mode
Defines the resampling method to use.
Definition AudioResampler.h:48
Definition AutomatableModel.h:77
Definition AutomatableModel.h:463
Definition GigPlayer.h:74
RIFF::File riff
Definition GigPlayer.h:82
gig::File gig
Definition GigPlayer.h:85
GigInstance(QString filename)
Definition GigPlayer.h:76
void deleteNotePluginData(NotePlayHandle *_n) override
Definition GigPlayer.cpp:663
gui::PluginView * instantiateView(QWidget *_parent) override
Create a view for the model.
Definition GigPlayer.cpp:687
void loadSettings(const QDomElement &_this) override
Definition GigPlayer.cpp:128
QMutex m_synthMutex
Definition GigPlayer.h:290
f_cnt_t getLoopedIndex(f_cnt_t index, f_cnt_t startf, f_cnt_t endf) const
Definition GigPlayer.cpp:630
void addSamples(GigNote &gignote, bool wantReleaseSample)
Definition GigPlayer.cpp:700
void play(SampleFrame *_working_buffer) override
Definition GigPlayer.cpp:320
float m_currentKeyDimension
Definition GigPlayer.h:298
QString getCurrentPatchName()
Definition GigPlayer.cpp:248
GigInstrument(InstrumentTrack *_instrument_track)
Definition GigPlayer.cpp:81
void updatePatch()
Definition GigPlayer.cpp:237
FloatModel m_gain
Definition GigPlayer.h:287
void setParameter(const QString &_param, const QString &_value)
mapPropertyFromModel(int, getPatch, setPatch, m_patchNum)
void loadSample(GigSample &sample, SampleFrame *sampleData, f_cnt_t samples)
Definition GigPlayer.cpp:494
uint32_t m_RandomSeed
Definition GigPlayer.h:297
QMutex m_notesMutex
Definition GigPlayer.h:291
mapPropertyFromModel(int, getBank, setBank, m_bankNum)
AutomatableModel * childModel(const QString &_modelName) override
Definition GigPlayer.cpp:155
GigInstance * m_instance
Definition GigPlayer.h:278
QString m_filename
Definition GigPlayer.h:282
gui::LcdSpinBoxModel m_patchNum
Definition GigPlayer.h:285
gui::LcdSpinBoxModel m_bankNum
Definition GigPlayer.h:284
void playNote(NotePlayHandle *_n, SampleFrame *_working_buffer) override
Definition GigPlayer.cpp:289
QString nodeName() const override
Definition GigPlayer.cpp:174
void getInstrument()
Definition GigPlayer.cpp:847
f_cnt_t getPingPongIndex(f_cnt_t index, f_cnt_t startf, f_cnt_t endf) const
Definition GigPlayer.cpp:644
gig::Instrument * m_instrument
Definition GigPlayer.h:279
Dimension getDimensions(gig::Region *pRegion, int velocity, bool release)
Definition GigPlayer.cpp:769
~GigInstrument() override
Definition GigPlayer.cpp:105
void loadFile(const QString &_file) override
Definition GigPlayer.cpp:142
QList< GigNote > m_notes
Definition GigPlayer.h:294
void updateSampleRate()
Definition GigPlayer.cpp:882
void openFile(const QString &_gigFile, bool updateTrackName=true)
Definition GigPlayer.cpp:203
void saveSettings(QDomDocument &_doc, QDomElement &_parent) override
Definition GigPlayer.cpp:116
void freeInstance()
Definition GigPlayer.cpp:182
Definition GigPlayer.h:208
GigState state
Definition GigPlayer.h:214
std::vector< GigSample > samples
Definition GigPlayer.h:216
GigNote(int midiNote, int velocity, float frequency, GIGPluginData *handle)
Definition GigPlayer.h:224
GIGPluginData * handle
Definition GigPlayer.h:222
bool isRelease
Definition GigPlayer.h:213
int velocity
Definition GigPlayer.h:211
bool release
Definition GigPlayer.h:212
float frequency
Definition GigPlayer.h:215
int midiNote
Definition GigPlayer.h:210
Definition GigPlayer.h:150
AudioResampler m_resampler
Definition GigPlayer.h:174
float freqFactor
Definition GigPlayer.h:182
std::span< SampleFrame > m_mixBufferView
Definition GigPlayer.h:178
std::array< SampleFrame, DEFAULT_BUFFER_SIZE > m_mixBuffer
Definition GigPlayer.h:176
GigSample(gig::Sample *pSample, gig::DimensionRegion *pDimRegion, float attenuation, AudioResampler::Mode interpolation, float desiredFreq)
Definition GigPlayer.cpp:1077
f_cnt_t pos
Definition GigPlayer.h:166
GigSample & operator=(const GigSample &g)
Definition GigPlayer.cpp:1120
float attenuation
Definition GigPlayer.h:162
ADSR adsr
Definition GigPlayer.h:163
gig::Sample * sample
Definition GigPlayer.h:160
float sampleFreq
Definition GigPlayer.h:181
std::span< SampleFrame > m_sourceBufferView
Definition GigPlayer.h:177
~GigSample()=default
std::array< SampleFrame, DEFAULT_BUFFER_SIZE > m_sourceBuffer
Definition GigPlayer.h:175
bool pitchtrack
Definition GigPlayer.h:171
gig::DimensionRegion * region
Definition GigPlayer.h:161
Definition Instrument.h:52
Instrument(InstrumentTrack *_instrument_track, const Descriptor *_descriptor, const Descriptor::SubPluginFeatures::Key *key=nullptr, Flags flags=Flag::NoFlags)
Definition Instrument.cpp:38
Definition InstrumentTrack.h:62
Definition NotePlayHandle.h:48
Definition SampleFrame.h:41
Definition GigPlayer.h:335
LcdSpinBox * m_bankNumLcd
Definition GigPlayer.h:348
Knob * m_gainKnob
Definition GigPlayer.h:354
static PatchesDialog * s_patchDialog
Definition GigPlayer.h:356
PixmapButton * m_patchDialogButton
Definition GigPlayer.h:346
QLabel * m_filenameLabel
Definition GigPlayer.h:351
LcdSpinBox * m_patchNumLcd
Definition GigPlayer.h:349
void updatePatchName()
Definition GigPlayer.cpp:1002
GigInstrumentView(Instrument *_instrument, QWidget *_parent)
Definition GigPlayer.cpp:907
PixmapButton * m_fileDialogButton
Definition GigPlayer.h:345
void showFileDialog()
Definition GigPlayer.cpp:1023
void showPatchDialog()
Definition GigPlayer.cpp:1064
void updateFilename()
Definition GigPlayer.cpp:984
void invalidateFile()
Definition GigPlayer.cpp:1015
QLabel * m_patchLabel
Definition GigPlayer.h:352
~GigInstrumentView() override=default
void modelChanged() override
Definition GigPlayer.cpp:967
Instrument view with fixed LMMS-default size.
Definition InstrumentView.h:66
Definition Knob.h:47
Definition LcdSpinBox.h:35
Definition PatchesDialog.h:44
Definition PixmapButton.h:37
Definition PluginView.h:36
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
unsigned int uint32_t
Definition mid.cpp:100
Definition AudioPortAudio.cpp:223
IntModel LcdSpinBoxModel
Definition LcdSpinBox.h:88
Definition AudioAlsa.cpp:35
GigState
Definition GigPlayer.h:190
@ Completed
Definition GigPlayer.h:200
@ KeyUp
Definition GigPlayer.h:196
@ PlayingKeyUp
Definition GigPlayer.h:198
@ PlayingKeyDown
Definition GigPlayer.h:194
@ KeyDown
Definition GigPlayer.h:192
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
QString filename
Definition HydrogenImport.cpp:42
#define false
Definition ordinals.h:83
Definition GigPlayer.h:93
uint DimValues[8]
Definition GigPlayer.h:103
Dimension()
Definition GigPlayer.h:94
bool release
Definition GigPlayer.h:104
Definition GigPlayer.h:65
int midiNote
Definition GigPlayer.h:66
signed int sample
Definition tap_dynamics_m.c:41