CSL  6.0
SpatialPanner.cpp
Go to the documentation of this file.
1 //
2 // SpatialPanner.cpp -- Specification of the abstract framework for panner/spatializers
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 // Created by Jorge Castellanos on 3/29/06. Hacked 8/09 by STP.
5 //
6 
7 #include "SpatialPanner.h"
8 
9 using namespace csl;
10 
12  : UnitGenerator(CGestalt::frameRate(), 2),
13  mSpeakerLayout(NULL) {
14 // mSources = (SpatialSource **) malloc(64 * sizeof(SpatialSource*));
15  mTempBuffer.setSize(1, CGestalt::blockSize()); // mono buffer for operations
17  setSpeakerLayout(layout); // Grab the default layout.
18 }
19 
21  mSpeakerLayout->detachObserver(this); // Remove yourself from the list of observers.
23 }
24 
26  // TO DO: FIRST CHECK TO MAKE SURE THERE'S A LAYOUT,
27  // THEN DETACH AS OBSERVER OF PREVIOUS AND ATTACH TO NEWER ONE!
28  if (aLayout == mSpeakerLayout) // If user is just setting the same layout again, do nothing.
29  return;
30 
31  if (mSpeakerLayout != NULL) // If still alive, remove yourself as an observer.
33 
34  mSpeakerLayout = aLayout;
35  mSpeakerLayout->attachObserver(this); // Tell the speaker layout to inform you of any changes
36  this->speakerLayoutChanged();
37 }
38 
39 // add a source and create a cache object
40 
42 // unsigned which = mSources.size();
43 // for (unsigned i = 0; i < which; i++) {
44 // if (mSources[i] == NULL) {
45 // which = i;
46 // break;
47 // }
48 // }
49 // mSources[which] = &soundSource;
50  mSources.push_back(&soundSource);
51  mCache.push_back(this->cache());
52 }
53 
54 // delete from the list, shifting if necessary
55 
57 // unsigned count = mSources.size();
58  for (unsigned i = 0; i < mSources.size(); i++) {
59  if (mSources[i] == &soundSource) {
60 // mSources[i] = NULL;
61  mSources.erase(mSources.begin() + i);
62  mCache.erase(mCache.begin() + i);
63  break;
64  }
65  }
66 #ifdef CSL_DEBUG
67  logMsg("Panner::removeSource");
68 #endif
69  return;
70 }
71 
73  return (void *)new float; // Returns a pointer to an alocated cache data for its own use.
74 }
75 
76 /**
77 Called when the speaker layout changes, so panners update their data.
78 This method is implemented only by the Panner class, and depending on the message sent, it calls
79 the appropriate method implemented by subclasses. For example, when the speaker layout changes,
80 the method calls "speakerLayoutChanged()", which should be implemented by subclasses interested to
81 react to such change.
82 */
83 void SpatialPanner::update(void * arg) {
84 // cout << "Panner::Updated Speaker Layout!" << mNumTriplets << endl;
85  // Re-calculate all the stuff.
86  if (mSpeakerLayout == NULL) // If it was destroyed get the default layout
88  // Update any info that depends on the layout
89  this->speakerLayoutChanged();
90 }
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
virtual ~SpatialPanner()
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
UGenVector mSources
SpatialSource... refers to its input UGen, but with the knowledge of its position within a space...
Definition: SpatialPanner.h:49
Buffer mTempBuffer
Buffer used to temporarily hold input source data.
Definition: SpatialPanner.h:54
virtual void * cache()
create the cache
void freeBuffers()
fcn to free them
Definition: CSL_Core.cpp:141
The CSL system defaults class.
Definition: CGestalt.h:39
void setSize(unsigned numChannels, unsigned numFrames)
Definition: CSL_Core.cpp:75
vector< void * > mCache
Vector of pointers to the prior I/O data.
Definition: SpatialPanner.h:50
static unsigned blockSize()
the default block size
Definition: CGestalt.cpp:57
Temp Spatial Sound Source.
Definition: SpatialSource.h:29
SpeakerLayout * mSpeakerLayout
If null, it will use the default layout by calling SpeakerLayout::defaultSpeakerLayout();.
Definition: SpatialPanner.h:52
virtual void removeSource(SpatialSource &s)
Remove a Sound Source.
virtual void addSource(SpatialSource &s)
number of active inputs.
virtual void speakerLayoutChanged()
Definition: SpatialPanner.h:57
virtual void update(void *arg)
Called when the speaker layout changes.
SpatialPanner(SpeakerLayout *layout=SpeakerLayout::defaultSpeakerLayout())
Constructor - a SpeakerLayout can be specified.
void detachObserver(Observer *)
Definition: CGestalt.cpp:518
void attachObserver(Observer *)
(possibly notify obersvers on my death)
Definition: CGestalt.cpp:502
void allocateBuffers()
fcn to malloc storage buffers
Definition: CSL_Core.cpp:122
forward declaration
Definition: CSL_Core.h:241
static SpeakerLayout * defaultSpeakerLayout()
Returns a pointer to the default layout. If no default exists, it creates one.
void setSpeakerLayout(SpeakerLayout *aLayout)
Set the speaker layout to be used by this panner. The panner will request the default layout if not s...