CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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