@@ -814,8 +814,7 @@ public: | |||||
internal->setCallback (callback); | internal->setCallback (callback); | ||||
if (callback != 0) | if (callback != 0) | ||||
callback->audioDeviceAboutToStart (internal->sampleRate, | |||||
internal->bufferSize); | |||||
callback->audioDeviceAboutToStart (this); | |||||
isStarted = (callback != 0); | isStarted = (callback != 0); | ||||
} | } | ||||
@@ -1001,8 +1001,7 @@ public: | |||||
if (internal != 0 && ! isStarted) | if (internal != 0 && ! isStarted) | ||||
{ | { | ||||
if (callback != 0) | if (callback != 0) | ||||
callback->audioDeviceAboutToStart (getCurrentSampleRate(), | |||||
getCurrentBufferSizeSamples()); | |||||
callback->audioDeviceAboutToStart (this); | |||||
isStarted = true; | isStarted = true; | ||||
internal->start (callback); | internal->start (callback); | ||||
@@ -763,7 +763,7 @@ public: | |||||
{ | { | ||||
if (callback != 0) | if (callback != 0) | ||||
{ | { | ||||
callback->audioDeviceAboutToStart (currentSampleRate, currentBlockSizeSamples); | |||||
callback->audioDeviceAboutToStart (this); | |||||
const ScopedLock sl (callbackLock); | const ScopedLock sl (callbackLock); | ||||
currentCallback = callback; | currentCallback = callback; | ||||
@@ -1162,7 +1162,7 @@ public: | |||||
return; | return; | ||||
} | } | ||||
call->audioDeviceAboutToStart (sampleRate, bufferSizeSamples); | |||||
call->audioDeviceAboutToStart (this); | |||||
const ScopedLock sl (startStopLock); | const ScopedLock sl (startStopLock); | ||||
callback = call; | callback = call; | ||||
@@ -414,8 +414,7 @@ void AudioDeviceManager::setAudioCallback (AudioIODeviceCallback* newCallback) | |||||
lastCallback->audioDeviceStopped(); | lastCallback->audioDeviceStopped(); | ||||
if (newCallback != 0) | if (newCallback != 0) | ||||
newCallback->audioDeviceAboutToStart (currentAudioDevice->getCurrentSampleRate(), | |||||
currentAudioDevice->getCurrentBufferSizeSamples()); | |||||
newCallback->audioDeviceAboutToStart (currentAudioDevice); | |||||
} | } | ||||
currentCallback = newCallback; | currentCallback = newCallback; | ||||
@@ -446,10 +445,13 @@ void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelDat | |||||
} | } | ||||
} | } | ||||
void AudioDeviceManager::audioDeviceAboutToStartInt (double sampleRate, int blockSize) | |||||
void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device) | |||||
{ | { | ||||
cpuUsageMs = 0; | cpuUsageMs = 0; | ||||
const double sampleRate = device->getCurrentSampleRate(); | |||||
const int blockSize = device->getCurrentBufferSizeSamples(); | |||||
if (sampleRate > 0.0 && blockSize > 0) | if (sampleRate > 0.0 && blockSize > 0) | ||||
{ | { | ||||
const double msPerBlock = 1000.0 * blockSize / sampleRate; | const double msPerBlock = 1000.0 * blockSize / sampleRate; | ||||
@@ -457,7 +459,7 @@ void AudioDeviceManager::audioDeviceAboutToStartInt (double sampleRate, int bloc | |||||
} | } | ||||
if (currentCallback != 0) | if (currentCallback != 0) | ||||
currentCallback->audioDeviceAboutToStart (sampleRate, blockSize); | |||||
currentCallback->audioDeviceAboutToStart (device); | |||||
sendChangeMessage (this); | sendChangeMessage (this); | ||||
} | } | ||||
@@ -603,9 +605,9 @@ void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** i | |||||
owner->audioDeviceIOCallbackInt (inputChannelData, totalNumInputChannels, outputChannelData, totalNumOutputChannels, numSamples); | owner->audioDeviceIOCallbackInt (inputChannelData, totalNumInputChannels, outputChannelData, totalNumOutputChannels, numSamples); | ||||
} | } | ||||
void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (double sampleRate, int blockSize) | |||||
void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device) | |||||
{ | { | ||||
owner->audioDeviceAboutToStartInt (sampleRate, blockSize); | |||||
owner->audioDeviceAboutToStartInt (device); | |||||
} | } | ||||
void AudioDeviceManager::CallbackHandler::audioDeviceStopped() | void AudioDeviceManager::CallbackHandler::audioDeviceStopped() | ||||
@@ -369,7 +369,7 @@ private: | |||||
int totalNumOutputChannels, | int totalNumOutputChannels, | ||||
int numSamples); | int numSamples); | ||||
void audioDeviceAboutToStart (double sampleRate, int blockSize); | |||||
void audioDeviceAboutToStart (AudioIODevice*); | |||||
void audioDeviceStopped(); | void audioDeviceStopped(); | ||||
@@ -385,7 +385,7 @@ private: | |||||
float** outputChannelData, | float** outputChannelData, | ||||
int totalNumOutputChannels, | int totalNumOutputChannels, | ||||
int numSamples); | int numSamples); | ||||
void audioDeviceAboutToStartInt (double sampleRate, int blockSize); | |||||
void audioDeviceAboutToStartInt (AudioIODevice* const device); | |||||
void audioDeviceStoppedInt(); | void audioDeviceStoppedInt(); | ||||
void handleIncomingMidiMessageInt (MidiInput* source, const MidiMessage& message); | void handleIncomingMidiMessageInt (MidiInput* source, const MidiMessage& message); | ||||
@@ -35,6 +35,7 @@ | |||||
#include "../../../juce_core/text/juce_StringArray.h" | #include "../../../juce_core/text/juce_StringArray.h" | ||||
#include "../../../juce_core/containers/juce_BitArray.h" | #include "../../../juce_core/containers/juce_BitArray.h" | ||||
#include "../../../juce_core/containers/juce_OwnedArray.h" | #include "../../../juce_core/containers/juce_OwnedArray.h" | ||||
class AudioIODevice; | |||||
//============================================================================== | //============================================================================== | ||||
@@ -103,13 +104,15 @@ public: | |||||
callback has just been added to an audio device, or after the device has been | callback has just been added to an audio device, or after the device has been | ||||
restarted because of a sample-rate or block-size change. | restarted because of a sample-rate or block-size change. | ||||
@param sampleRate the sample rate it's going to use | |||||
@param numSamplesPerBlock the intended block size - this isn't a guaranteed | |||||
figure; see the notes about numSamples in the | |||||
audioDeviceIOCallback() method. | |||||
You can use this opportunity to find out the sample rate and block size | |||||
that the device is going to use by calling the AudioIODevice::getCurrentSampleRate() | |||||
and AudioIODevice::getCurrentBufferSizeSamples() on the supplied pointer. | |||||
@param device the audio IO device that will be used to drive the callback. | |||||
Note that if you're going to store this this pointer, it is | |||||
only valid until the next time that audioDeviceStopped is called. | |||||
*/ | */ | ||||
virtual void audioDeviceAboutToStart (double sampleRate, | |||||
int numSamplesPerBlock) = 0; | |||||
virtual void audioDeviceAboutToStart (AudioIODevice* device) = 0; | |||||
/** Called to indicate that the device has stopped. | /** Called to indicate that the device has stopped. | ||||
*/ | */ | ||||
@@ -316,7 +316,7 @@ void AudioSampleBuffer::addFrom (const int destChannel, | |||||
int numSamples, | int numSamples, | ||||
const float gain) throw() | const float gain) throw() | ||||
{ | { | ||||
jassert (&source != this); | |||||
jassert (&source != this || sourceChannel != destChannel); | |||||
jassert (((unsigned int) destChannel) < (unsigned int) numChannels); | jassert (((unsigned int) destChannel) < (unsigned int) numChannels); | ||||
jassert (destStartSample >= 0 && destStartSample + numSamples <= size); | jassert (destStartSample >= 0 && destStartSample + numSamples <= size); | ||||
jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels); | jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels); | ||||
@@ -409,7 +409,7 @@ void AudioSampleBuffer::copyFrom (const int destChannel, | |||||
const int sourceStartSample, | const int sourceStartSample, | ||||
int numSamples) throw() | int numSamples) throw() | ||||
{ | { | ||||
jassert (&source != this); | |||||
jassert (&source != this || sourceChannel != destChannel); | |||||
jassert (((unsigned int) destChannel) < (unsigned int) numChannels); | jassert (((unsigned int) destChannel) < (unsigned int) numChannels); | ||||
jassert (destStartSample >= 0 && destStartSample + numSamples <= size); | jassert (destStartSample >= 0 && destStartSample + numSamples <= size); | ||||
jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels); | jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels); | ||||
@@ -53,9 +53,14 @@ MidiBuffer::MidiBuffer (const MidiBuffer& other) throw() | |||||
const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() | const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() | ||||
{ | { | ||||
bytesUsed = other.bytesUsed; | |||||
ensureAllocatedSize (bytesUsed); | |||||
memcpy (elements, other.elements, bytesUsed); | |||||
if (this != &other) | |||||
{ | |||||
bytesUsed = other.bytesUsed; | |||||
ensureAllocatedSize (bytesUsed); | |||||
if (bytesUsed > 0) | |||||
memcpy (elements, other.elements, bytesUsed); | |||||
} | |||||
return *this; | return *this; | ||||
} | } | ||||