CSL  6.0
Instrument.h
Go to the documentation of this file.
1 ///
2 /// Instrument.h -- The CSL pluggable instrument class.
3 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 ///
5 /// Instrument are reflective objects that hold onto a DSP graph (a UnitGen), a name, and a list of "plugs"
6 /// (Accessors, mapped to MIDI or OSC messages) for external control.
7 /// Instruments can be registered with MIDI voicers or in the OSC address space.
8 
9 #ifndef INCLUDE_Instrument_H
10 #define INCLUDE_Instrument_H
11 
12 #include "CSL_Includes.h"
13 #include "Accessor.h"
14 
15 ///
16 /// Keys for setParameter selector (default parameters for all notes)
17 ///
18 
19 #define set_duration_f 100 // basic accessors: dur, amp, freq, pos
20 #define set_amplitude_f 101
21 #define set_frequency_f 102
22 #define set_position_f 103 // position as a float or a point
23 #define set_position_p 104
24 
25 #define set_attack_f 105 // ADSR envelope
26 #define set_decay_f 106
27 #define set_sustain_f 107
28 #define set_release_f 108
29 
30 #define set_iattack_f 110 // 2nd ADSR envelope (index, mod)
31 #define set_idecay_f 111
32 #define set_isustain_f 112
33 #define set_irelease_f 113
34 
35 #define set_index_f 114 // Various frequencies
36 #define set_c_freq_f 115
37 #define set_m_freq_f 116
38 
39 #define set_vib_depth_f 120 // Vibrato, attack-chiff
40 #define set_chiff_amt_f 121
41 #define set_chiff_time_f 122
42 
43 #define set_rate_f 125 // Sampler file, start, stop, rate
44 #define set_file_f 126
45 #define set_start_f 127
46 #define set_stop_f 128
47 
48 #define set_partial_f 130 // SumOfSines partial and partial list
49 #define set_partials_f 131
50 
51 namespace csl {
52 
53 ///
54 /// Instrument class (abstract)
55 ///
56 class Instrument : public UnitGenerator {
57 public:
58  /// Constructors
59  Instrument();
60  Instrument(Instrument&); ///< copy constructor
61  ~Instrument();
62  /// Accessors
63  UnitGenerator * graph() { return mGraph; }; ///< my UGen graph
64  UGenMap * genMap() { return & mUGens; }; ///< the map of ugens in the graph by name
65  UGenVector * envelopes() { return & mEnvelopes; }; ///< the vector of envelopes to query or trigger
66 
67  const string name() { return mName; }; ///< answer my name
68  /// answer the number of channels
69  UnitGenerator * genNamed(string name); ///< get a UGen from the graph
70 
71  /// Accessor management
72  AccessorVector getAccessors() { return mAccessors; }; ///< answer the accessor vector
73  unsigned numAccessors() { return mAccessors.size(); }; ///< answer the number of accessors
74  virtual void setParameter(unsigned selector, int argc, void **argv, const char *types) { }; ///< set a named parameter
75 // virtual float getParameter(unsigned selector);
76 
77  virtual void nextBuffer(Buffer & outputBuffer) throw (CException); ///< Sample creation
78 
79  virtual bool isActive(); ///< Envelope query and re-trigger
80  virtual void play();
81  virtual void playOSC(int argc, void **argv, const char *types) { }; ///< Play a note (subclasses refine)
82  virtual void playNote(int argc, void **argv, const char *types) { };
83  virtual void playMIDI(float dur, int chan, int key, int vel) { };
84  virtual void release();
85 
86 protected: /// Caches
87  UnitGenerator * mGraph; ///< my UGen graph
88  string mName; ///< my name
89  UGenMap mUGens; ///< the map of ugens in the graph by name
90  UGenVector mEnvelopes; ///< the vector of envelopes to query or trigger
91  AccessorVector mAccessors; ///< the accessor vector
92 };
93 
94 }
95 
96 #endif
virtual void nextBuffer(Buffer &outputBuffer)
set a named parameter
Definition: Instrument.cpp:41
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
virtual void playNote(int argc, void **argv, const char *types)
Play a note (subclasses refine)
Definition: Instrument.h:82
virtual void playMIDI(float dur, int chan, int key, int vel)
Definition: Instrument.h:83
UnitGenerator * mGraph
Caches.
Definition: Instrument.h:87
virtual void release()
Definition: Instrument.cpp:76
UnitGenerator * graph()
Accessors.
Definition: Instrument.h:63
AccessorVector mAccessors
the accessor vector
Definition: Instrument.h:91
AccessorVector getAccessors()
Accessor management.
Definition: Instrument.h:72
virtual void play()
Definition: Instrument.cpp:70
string mName
my name
Definition: Instrument.h:88
UGenMap * genMap()
my UGen graph
Definition: Instrument.h:64
UGenVector * envelopes()
the map of ugens in the graph by name
Definition: Instrument.h:65
std::map< std::string, UnitGenerator * > UGenMap
UGenMap: a named map of unit generators (used for GUIs)
Definition: CSL_Types.h:243
Instrument class (abstract)
Definition: Instrument.h:56
std::vector< UnitGenerator * > UGenVector
Definition: CSL_Types.h:241
vector< Accessor * > AccessorVector
Typedef for AccessorVector object.
Definition: Accessor.h:39
virtual bool isActive()
Envelope query and re-trigger.
Definition: Instrument.cpp:57
const string name()
the vector of envelopes to query or trigger
Definition: Instrument.h:67
virtual void setParameter(unsigned selector, int argc, void **argv, const char *types)
answer the number of accessors
Definition: Instrument.h:74
UnitGenerator * genNamed(string name)
answer my name answer the number of channels
Definition: Instrument.cpp:47
unsigned numAccessors()
answer the accessor vector
Definition: Instrument.h:73
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
Instrument()
Constructors.
Definition: Instrument.cpp:12
forward declaration
Definition: CSL_Core.h:241
virtual void playOSC(int argc, void **argv, const char *types)
Definition: Instrument.h:81
UGenVector mEnvelopes
the vector of envelopes to query or trigger
Definition: Instrument.h:90
Base class of CSL exceptions (written upper-case). Has a string message.
UGenMap mUGens
the map of ugens in the graph by name
Definition: Instrument.h:89