-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstrument.h
138 lines (110 loc) · 4.1 KB
/
Instrument.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Instrument.h - declaration of class Instrument, which provides a
* standard interface for all instrument plugins
*
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef _INSTRUMENT_H
#define _INSTRUMENT_H
#include <QtGui/QWidget>
#include "Plugin.h"
#include "Mixer.h"
// forward-declarations
class InstrumentTrack;
class InstrumentView;
class MidiEvent;
class MidiTime;
class NotePlayHandle;
class track;
class EXPORT Instrument : public Plugin
{
public:
Instrument( InstrumentTrack * _instrument_track,
const Descriptor * _descriptor );
virtual ~Instrument();
// --------------------------------------------------------------------
// functions that can/should be re-implemented:
// --------------------------------------------------------------------
// if the plugin doesn't play each note, it can create an instrument-
// play-handle and re-implement this method, so that it mixes its
// output buffer only once per mixer-period
virtual void play( sampleFrame * _working_buffer );
// to be implemented by actual plugin
virtual void playNote( NotePlayHandle * /* _note_to_play */,
sampleFrame * /* _working_buf */ )
{
}
// needed for deleting plugin-specific-data of a note - plugin has to
// cast void-ptr so that the plugin-data is deleted properly
// (call of dtor if it's a class etc.)
virtual void deleteNotePluginData( NotePlayHandle * _note_to_play );
// Get number of sample-frames that should be used when playing beat
// (note with unspecified length)
// Per default this function returns 0. In this case, channel is using
// the length of the longest envelope (if one active).
virtual f_cnt_t beatLen( NotePlayHandle * _n ) const;
// some instruments need a certain number of release-frames even
// if no envelope is active - such instruments can re-implement this
// method for returning how many frames they at least like to have for
// release
virtual f_cnt_t desiredReleaseFrames() const
{
return 0;
}
// return false if instrument is not bendable
inline virtual bool isBendable() const
{
return true;
}
// return true if instruments reacts to MIDI events passed to
// handleMidiEvent() rather than playNote() & Co
inline virtual bool isMidiBased() const
{
return false;
}
// sub-classes can re-implement this for receiving all incoming
// MIDI-events
inline virtual bool handleMidiEvent( const MidiEvent&, const MidiTime& = MidiTime() )
{
return true;
}
virtual QString fullDisplayName() const;
// --------------------------------------------------------------------
// provided functions:
// --------------------------------------------------------------------
// instantiate instrument-plugin with given name or return NULL
// on failure
static Instrument * instantiate( const QString & _plugin_name,
InstrumentTrack * _instrument_track );
virtual bool isFromTrack( const track * _track ) const;
protected:
inline InstrumentTrack * instrumentTrack() const
{
return m_instrumentTrack;
}
// instruments may use this to apply a soft fade out at the end of
// notes - method does this only if really less or equal
// desiredReleaseFrames() frames are left
void applyRelease( sampleFrame * buf, const NotePlayHandle * _n );
private:
InstrumentTrack * m_instrumentTrack;
} ;
#endif