CSL  6.0
Instrument.cpp
Go to the documentation of this file.
1 //
2 // Instrument.cpp -- The CSL pluggable instrument class.
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 
6 #include "Instrument.h"
7 
8 using namespace csl;
9 
10 // Constructors
11 
13  UnitGenerator(),
14  mGraph(0),
15  mName("New"),
16  mUGens(),
17  mEnvelopes(),
18  mAccessors() { }
19 
20 // copy constructor
21 
23  UnitGenerator(in.frameRate(), in.numChannels()),
24  mGraph(in.graph()),
25  mName(in.name()) {
26  UGenVector * en = in.envelopes();
27  for (unsigned i = 0; i < en->size(); i++)
28  mEnvelopes.push_back((*en)[i]);
29  AccessorVector av = in.getAccessors();
30  for (unsigned i = 0; i < av.size(); i++)
31  mAccessors.push_back(av[i]);
32  UGenMap * um = in.genMap();
33  for (UGenMap::iterator it = um->begin(); it != um->end(); it++)
34  mUGens[it->first] = it->second;
35 }
36 
38 
39 // Next_buffer is simply delegated to the receiver's graph
40 
41 void Instrument::nextBuffer(Buffer & outputBuffer) throw (CException) {
42  return (mGraph->nextBuffer(outputBuffer));
43 }
44 
45 ///< get a UGen from the graph
46 
48  UGenMap::iterator pos = mUGens.find(nam);
49  if (pos == mUGens.end())
50  return 0;
51  return (pos->second);
52 }
53 
54 // Answer whether any of the envelopes are active
55 // NB: This is a rare use of std::vector iteration (instead of an Accessor* for () loop) at call-back time.
56 
58  if (mEnvelopes.empty()) {
59 // printf(" -- No envs -- "); fflush(stdout);
60  return (mGraph->isActive());
61  }
62  for (UGenVector::iterator pos = mEnvelopes.begin(); pos != mEnvelopes.end(); ++pos)
63  if (((Envelope *) *pos)->isActive())
64  return TRUE;
65  return FALSE;
66 }
67 
68 // Playing a note just means triggering all the instrument's envelopes
69 
71 // printf("\tInstr play\n");
72  for (UGenVector::iterator pos = mEnvelopes.begin(); pos != mEnvelopes.end(); ++pos)
73  ((Envelope *) *pos)->trigger();
74 }
75 
77  for (UGenVector::iterator pos = mEnvelopes.begin(); pos != mEnvelopes.end(); ++pos)
78  ((Envelope *) *pos)->trigger();
79 }
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
UnitGenerator * mGraph
Caches.
Definition: Instrument.h:87
virtual void release()
Definition: Instrument.cpp:76
AccessorVector mAccessors
the accessor vector
Definition: Instrument.h:91
AccessorVector getAccessors()
Accessor management.
Definition: Instrument.h:72
virtual void play()
Definition: Instrument.cpp:70
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
#define FALSE
Definition: CSL_Types.h:329
virtual void trigger()
Definition: CSL_Core.h:288
virtual bool isActive()
query whether I'm currently active (Envelopes can go inactive)
Definition: CSL_Core.h:273
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
#define TRUE
Definition: CSL_Types.h:328
UnitGenerator * genNamed(string name)
answer my name answer the number of channels
Definition: Instrument.cpp:47
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
UGenVector mEnvelopes
the vector of envelopes to query or trigger
Definition: Instrument.h:90
Envelope: a collection of LineSegments; may have an input (scale) and act like a processor, or have no input and act like a control UGen. I inherit Scalable setScale, setOffset for inputs.
Definition: Envelope.h:89
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