Jamoma API  0.6.0.a19
TTMuteSolo.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief ##TTMutesolo mutes and soloes channels.
6  *
7  * @authors Trond Lossius
8  *
9  * @copyright Copyright © 2014, Trond Lossius @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 #include "TTMuteSolo.h"
16 
17 #define thisTTClass TTMutesolo
18 #define thisTTClassName "mutesolo"
19 #define thisTTClassTags "dspEffectsLib, audio, processor"
20 
21 
22 TT_AUDIO_CONSTRUCTOR,
23 mInterpolated(0)
24 {
25  TTChannelCount initialMaxNumChannels = arguments;
26 
27  // Initially we have no information stored for any channels
28  mStoredStateNumChannels = 0;
29 
30  // Register our attributes
31  addAttribute(Interpolated, kTypeBoolean);
32 
33  // Register messages
34  addMessageWithArguments(setChannelMute);
35  addMessageWithArguments(getChannelMute);
36  addMessageWithArguments(setChannelSolo);
37  addMessageWithArguments(getChannelSolo);
38  addMessage(clear);
39 
40  // Register for notifications from the parent class so we can allocate memory as required
41  addUpdates(MaxNumChannels);
42 
43  // Set defaults
44  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
45  clear();
46  setProcessMethod(processAudio);
47 }
48 
49 
50 TTMutesolo::~TTMutesolo()
51 {
52  ;
53 }
54 
55 
57 {
60  updateGains();
61  return kTTErrNone;
62 }
63 
64 
66 {
67  TTChannelCount numSoloedChannels = 0;
68 
69  // Mute channels, and count the number of soloed channels
70  for (TTChannelCount i=0; i<mStoredStateNumChannels; i++) {
71  gain[i] = 1.0 - mChannelMute[i];
72  if (mChannelSolo[i])
73  numSoloedChannels++;
74  }
75  // If at least one channel is soloed, soloing takes presedence over muting
76  if (numSoloedChannels>0) {
77  for (TTChannelCount i=0; i<mStoredStateNumChannels; i++) {
78  gain[i] = mChannelSolo[i];
79  }
80  }
81 
82  if (mInterpolated)
84 
85  return kTTErrNone;
86 }
87 
88 
89 
91 {
92  TTChannelCount channel;
93 
94  if (aValue.size() < 2)
95  return kTTErrWrongNumValues;
96  else {
97  channel = aValue[0];
98 
99  // It might be necessary to increase the number of channels tracked (channels count from 0, so adding 1)
101 
102  // Need to test for floating point as well as integer
103  if ((aValue[1] == 0.) || (aValue[1] == 0))
104  mChannelMute[channel] = 0.;
105  else
106  mChannelMute[channel] = 1.;
107 
108  return updateGains();
109  }
110 }
111 
112 
114 {
115  TTChannelCount channel;
116 
117  if (aValue.size() < 2)
118  return kTTErrWrongNumValues;
119  else {
120  channel = aValue[0];
121 
122  // It might be necessary to increase the number of channels tracked (channels count from 0, so adding 1)
124 
125  // Need to test for floating point as well as integer
126  if ((aValue[1] == 0.) || (aValue[1] == 0))
127  mChannelSolo[channel] = 0.;
128  else
129  mChannelSolo[channel] = 1.;
130 
131  return updateGains();
132  }
133 }
134 
135 
137 {
138  // Report the state for all channels, even if not all of them cureently are being processed.
139  aMuteValues.resize(mStoredStateNumChannels);
140 
141  for (TTChannelCount i=0; i<mStoredStateNumChannels; i++) {
142  aMuteValues[i] = mChannelMute[i];
143  }
144  return kTTErrNone;
145 }
146 
147 
149 {
150  // Report the state for all channels, even if not all of them cureently are being processed.
151  aSoloValues.resize(mStoredStateNumChannels);
152 
153  for (TTChannelCount i=0; i<mStoredStateNumChannels; i++) {
154  aSoloValues[i] = mChannelSolo[i];
155  }
156  return kTTErrNone;
157 }
158 
159 
161 {
162  // mStoredStateNumChannels might need to be increased.
164 }
165 
166 
168 {
169  // Only resize if the vector size need to be increased
170  // In the AudioGraph Max implementation (j.mutesolo=) this permits channel solo and mute values to be set before audio/AudioGraph has processed (and hence before the object knows how many channels are to be process).
171  if (aDesiredChannel > mStoredStateNumChannels) {
172 
173  mStoredStateNumChannels = aDesiredChannel;
174 
175  // The resize() method maintains all pre-existing values
178 
179  gain.resize(mStoredStateNumChannels, 0.);
180  oldGain.resize(mStoredStateNumChannels, 0.);
181 
182  updateGains();
183  }
184  return kTTErrNone;
185 }
186 
187 
189 {
190  TTAudioSignal& in = inputs->getSignal(0);
191  TTAudioSignal& out = outputs->getSignal(0);
192  TTUInt16 vs;
193  TTSampleValue *inSample, *outSample;
194  TTChannelCount numchannels = TTAudioSignal::getMinChannelCount(in, out);
195  TTChannelCount channel;
196 
197  for (channel=0; channel<numchannels; channel++) {
198  inSample = in.mSampleVectors[channel];
199  outSample = out.mSampleVectors[channel];
200  vs = in.getVectorSizeAsInt();
201  while (vs--)
202  *outSample++ = (*inSample++) * gain[channel];
203  }
204  return kTTErrNone;
205 }
206 
207 
209 {
210  TTAudioSignal& in = inputs->getSignal(0);
211  TTAudioSignal& out = outputs->getSignal(0);
212  TTUInt16 vs = in.getVectorSizeAsInt();
213  TTSampleValue *inSample, *outSample;
214  TTChannelCount numchannels = TTAudioSignal::getMinChannelCount(in, out);
215  TTChannelCount channel;
216  TTFloat64 increment, temp;
217 
218  for (channel=0; channel<numchannels; channel++) {
219  increment = (gain[channel] - oldGain[channel])/vs;
220  TTAntiDenormal(increment);
221  temp = oldGain[channel];
222 
223  inSample = in.mSampleVectors[channel];
224  outSample = out.mSampleVectors[channel];
225  vs = in.getVectorSizeAsInt();
226 
227  while (vs--){
228  temp = temp + increment;
229  *outSample++ = (*inSample++) * temp;
230  }
231  oldGain[channel] = gain[channel];
232  }
233 
235  return kTTErrNone;
236 }
TTErr getChannelSolo(const TTValue &, TTValue &aSoloValues)
Get current solo settings for all channels as an array.
Definition: TTMuteSolo.cpp:148
TTSampleVector mChannelMute
mute status for each channel
Definition: TTMuteSolo.h:37
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr increaseStoredStateNumChannels(TTChannelCount aDesiredChannel)
If there is a need to store mute/solo information for a channel that is not yet tracked, the number of channels that information need to be stored for is increased.
Definition: TTMuteSolo.cpp:167
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTErr setChannelMute(const TTValue &aValue, TTValue &)
Set whether one of the channels is muted or not.
Definition: TTMuteSolo.cpp:90
TTErr processAudioInterpolated(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Alternative audio processing method that might be used temporarily when mute or solo settings has bee...
Definition: TTMuteSolo.cpp:208
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Receives notifications when there are changes to the inherited maxNumChannels attribute.
Definition: TTMuteSolo.cpp:160
size_type size() const noexcept
Return the number of elements.
The wrong number of values were passed to a method or attribute.
Definition: TTBase.h:350
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTBoolean mInterpolated
Flag indicating whether interpolation will be applied when gain is changed.
Definition: TTMuteSolo.h:31
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTChannelCount mStoredStateNumChannels
The number of channels that mute and solo states are currently stored for. This might be higher than ...
Definition: TTMuteSolo.h:33
TTErr clear()
Clear all current mute and solo settings.
Definition: TTMuteSolo.cpp:56
TTErr updateGains()
Update gain values in response to current mute and solo settings.
Definition: TTMuteSolo.cpp:65
TTSampleVector gain
Gain value for each channel, depends on current settings for mute and solo.
Definition: TTMuteSolo.h:39
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
Definition: TTMuteSolo.cpp:188
TTMutesolo mutes and soloes channels.
TTErr getChannelMute(const TTValue &, TTValue &aMuteValues)
Get current mute settings for all channels as an array.
Definition: TTMuteSolo.cpp:136
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTSampleVector mChannelSolo
solo status for each channel. Soloing takes presedence over muting.
Definition: TTMuteSolo.h:35
A simple container for an array of TTAudioSignal pointers.
TTErr setChannelSolo(const TTValue &aValue, TTValue &)
Set whether one of the channels is soloed or not.
Definition: TTMuteSolo.cpp:113
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
TTSampleVector oldGain
Previous gain value for each channel, used when interpolating to new settings.
Definition: TTMuteSolo.h:41
void resize(size_type n)
Change the number of elements.
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44