diff options
Diffstat (limited to 'libs/appleutility/CoreAudio/AudioUnits/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp')
-rw-r--r-- | libs/appleutility/CoreAudio/AudioUnits/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/libs/appleutility/CoreAudio/AudioUnits/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp b/libs/appleutility/CoreAudio/AudioUnits/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp index 1ce8b308b4..74336d92e0 100644 --- a/libs/appleutility/CoreAudio/AudioUnits/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp +++ b/libs/appleutility/CoreAudio/AudioUnits/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp @@ -2,14 +2,14 @@ File: AUInstrumentBase.cpp Abstract: AUInstrumentBase.h Version: 1.1 - + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. - + In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the @@ -25,13 +25,13 @@ implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. - + The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. - + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS @@ -40,9 +40,9 @@ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + Copyright (C) 2014 Apple Inc. All Rights Reserved. - + */ #include "AUInstrumentBase.h" #include "AUMIDIDefs.h" @@ -58,12 +58,12 @@ const UInt32 kEventQueueSize = 1024; AUInstrumentBase::AUInstrumentBase( - AudioComponentInstance inInstance, + AudioComponentInstance inInstance, UInt32 numInputs, UInt32 numOutputs, UInt32 numGroups, UInt32 numParts) - : MusicDeviceBase(inInstance, numInputs, numOutputs, numGroups), + : MusicDeviceBase(inInstance, numInputs, numOutputs, numGroups), mAbsoluteSampleFrame(0), mEventQueue(kEventQueueSize), mNumNotes(0), @@ -79,7 +79,7 @@ AUInstrumentBase::AUInstrumentBase( mFreeNotes.mState = kNoteState_Free; SetWantsRenderThreadID(true); } - + AUInstrumentBase::~AUInstrumentBase() { @@ -100,12 +100,12 @@ AUElement * AUInstrumentBase::CreateElement(AudioUnitScope inScope, AudioUnitEle return MusicDeviceBase::CreateElement(inScope, element); } -void AUInstrumentBase::CreateExtendedElements() +void AUInstrumentBase::CreateExtendedElements() { Parts().Initialize(this, kAudioUnitScope_Part, mInitNumPartEls); } -AUScope * AUInstrumentBase::GetScopeExtended (AudioUnitScope inScope) +AUScope * AUInstrumentBase::GetScopeExtended (AudioUnitScope inScope) { if (inScope == kAudioUnitScope_Part) return &mPartScope; @@ -122,7 +122,7 @@ void AUInstrumentBase::SetNotes(UInt32 inNumNotes, UInt32 inMaxActiveNotes, Syn mMaxActiveNotes = inMaxActiveNotes; mNoteSize = inNoteDataSize; mNotes = inNotes; - + for (UInt32 i=0; i<mNumNotes; ++i) { SynthNote *note = GetNote(i); @@ -138,7 +138,7 @@ UInt32 AUInstrumentBase::CountActiveNotes() for (UInt32 i=0; i<mNumNotes; ++i) { SynthNote *note = GetNote(i); - if (note->GetState() <= kNoteState_Released) + if (note->GetState() <= kNoteState_Released) sum++; } return sum; @@ -165,16 +165,16 @@ OSStatus AUInstrumentBase::Initialize() TO DO: Currently ValidFormat will check and validate that the num channels is not being changed if the AU doesn't support the SupportedNumChannels property - which is correct - + What needs to happen here is that IFF the AU does support this property, (ie, the AU can be configured to have different num channels than its original configuration) then the state of the AU at Initialization needs to be validated. - + This is work still to be done - see AUEffectBase for the kind of logic that needs to be applied here */ // override to call SetNotes - + mNoteIDCounter = 128; // reset this every time we initialise mAbsoluteSampleFrame = 0; return noErr; @@ -199,7 +199,7 @@ OSStatus AUInstrumentBase::Reset( AudioUnitScope inScope, for (UInt32 i=0; i<mNumNotes; ++i) { SynthNote *note = GetNote(i); - if (note->IsSounding()) + if (note->IsSounding()) note->Kill(0); note->ListRemove(); mFreeNotes.AddNote(note); @@ -225,7 +225,7 @@ void AUInstrumentBase::PerformEvents(const AudioTimeStamp& inTimeStamp) #endif SynthEvent *event; SynthGroupElement *group; - + while ((event = mEventQueue.ReadItem()) != NULL) { #if DEBUG_PRINT_RENDER @@ -270,12 +270,12 @@ void AUInstrumentBase::PerformEvents(const AudioTimeStamp& inTimeStamp) group->ResetAllControllers(event->GetOffsetSampleFrame()); break; } - + mEventQueue.AdvanceReadPtr(); } } - + OSStatus AUInstrumentBase::Render( AudioUnitRenderActionFlags & ioActionFlags, const AudioTimeStamp & inTimeStamp, UInt32 inNumberFrames) @@ -311,18 +311,18 @@ OSStatus AUInstrumentBase::Render( AudioUnitRenderActionFlags & ioActionFlag bool AUInstrumentBase::ValidFormat( AudioUnitScope inScope, AudioUnitElement inElement, const CAStreamBasicDescription & inNewFormat) -{ +{ // if the AU supports this, then we should just let this go through to the Init call - if (SupportedNumChannels (NULL)) + if (SupportedNumChannels (NULL)) return MusicDeviceBase::ValidFormat(inScope, inElement, inNewFormat); bool isGood = MusicDeviceBase::ValidFormat (inScope, inElement, inNewFormat); if (!isGood) return false; - + // if we get to here, then the basic criteria is that the // num channels cannot change on an existing bus AUIOElement *el = GetIOElement (inScope, inElement); - return (el->GetStreamFormat().NumberChannels() == inNewFormat.NumberChannels()); + return (el->GetStreamFormat().NumberChannels() == inNewFormat.NumberChannels()); } @@ -333,8 +333,8 @@ bool AUInstrumentBase::StreamFormatWritable( AudioUnitScope scope, } OSStatus AUInstrumentBase::RealTimeStartNote( SynthGroupElement *inGroup, - NoteInstanceID inNoteInstanceID, - UInt32 inOffsetSampleFrame, + NoteInstanceID inNoteInstanceID, + UInt32 inOffsetSampleFrame, const MusicDeviceNoteParams &inParams) { return noErr; @@ -358,10 +358,10 @@ SynthGroupElement * AUInstrumentBase::GetElForGroupID (MusicDeviceGroupID inGrou AUScope & groups = Groups(); unsigned int numEls = groups.GetNumberOfElements(); SynthGroupElement* unassignedEl = NULL; - + for (unsigned int i = 0; i < numEls; ++i) { SynthGroupElement* el = reinterpret_cast<SynthGroupElement*>(groups.GetElement(i)); - if (el->GroupID() == inGroupID) + if (el->GroupID() == inGroupID) return el; if (el->GroupID() == SynthGroupElement::kUnassignedGroup) { unassignedEl = el; @@ -376,14 +376,14 @@ SynthGroupElement * AUInstrumentBase::GetElForGroupID (MusicDeviceGroupID inGrou } OSStatus AUInstrumentBase::RealTimeStopNote( - MusicDeviceGroupID inGroupID, - NoteInstanceID inNoteInstanceID, + MusicDeviceGroupID inGroupID, + NoteInstanceID inNoteInstanceID, UInt32 inOffsetSampleFrame) { #if DEBUG_PRINT printf("AUInstrumentBase::RealTimeStopNote ch %d id %d\n", inGroupID, inNoteInstanceID); #endif - + SynthGroupElement *gp = (inGroupID == kMusicNoteEvent_Unused ? GetElForNoteID (inNoteInstanceID) : GetElForGroupID(inGroupID)); @@ -391,7 +391,7 @@ OSStatus AUInstrumentBase::RealTimeStopNote( { gp->NoteOff (inNoteInstanceID, inOffsetSampleFrame); } - + return noErr; } @@ -402,7 +402,7 @@ SynthGroupElement * AUInstrumentBase::GetElForNoteID (NoteInstanceID inNoteID) #endif AUScope & groups = Groups(); unsigned int numEls = groups.GetNumberOfElements(); - + for (unsigned int i = 0; i < numEls; ++i) { SynthGroupElement* el = reinterpret_cast<SynthGroupElement*>(groups.GetElement(i)); if (el->GetNote(inNoteID) != NULL) // searches for any note state @@ -411,27 +411,27 @@ SynthGroupElement * AUInstrumentBase::GetElForNoteID (NoteInstanceID inNoteID) throw static_cast<OSStatus>(kAudioUnitErr_InvalidElement); } -OSStatus AUInstrumentBase::StartNote( MusicDeviceInstrumentID inInstrument, - MusicDeviceGroupID inGroupID, - NoteInstanceID * outNoteInstanceID, - UInt32 inOffsetSampleFrame, +OSStatus AUInstrumentBase::StartNote( MusicDeviceInstrumentID inInstrument, + MusicDeviceGroupID inGroupID, + NoteInstanceID * outNoteInstanceID, + UInt32 inOffsetSampleFrame, const MusicDeviceNoteParams &inParams) { OSStatus err = noErr; - - NoteInstanceID noteID; + + NoteInstanceID noteID; if (outNoteInstanceID) { noteID = NextNoteID(); *outNoteInstanceID = noteID; } else noteID = (UInt32)inParams.mPitch; - + #if DEBUG_PRINT printf("AUInstrumentBase::StartNote ch %u, key %u, offset %u\n", inGroupID, (unsigned) inParams.mPitch, inOffsetSampleFrame); #endif if (InRenderThread ()) - { + { err = RealTimeStartNote( GetElForGroupID(inGroupID), noteID, @@ -450,14 +450,14 @@ OSStatus AUInstrumentBase::StartNote( MusicDeviceInstrumentID inInstrument, inOffsetSampleFrame, &inParams ); - + mEventQueue.AdvanceWritePtr(); } return err; } -OSStatus AUInstrumentBase::StopNote( MusicDeviceGroupID inGroupID, - NoteInstanceID inNoteInstanceID, +OSStatus AUInstrumentBase::StopNote( MusicDeviceGroupID inGroupID, + NoteInstanceID inNoteInstanceID, UInt32 inOffsetSampleFrame) { #if DEBUG_PRINT @@ -466,7 +466,7 @@ OSStatus AUInstrumentBase::StopNote( MusicDeviceGroupID inGroupID, OSStatus err = noErr; if (InRenderThread ()) - { + { err = RealTimeStopNote( inGroupID, inNoteInstanceID, @@ -484,7 +484,7 @@ OSStatus AUInstrumentBase::StopNote( MusicDeviceGroupID inGroupID, inOffsetSampleFrame, NULL ); - + mEventQueue.AdvanceWritePtr(); } return err; @@ -492,13 +492,13 @@ OSStatus AUInstrumentBase::StopNote( MusicDeviceGroupID inGroupID, OSStatus AUInstrumentBase::SendPedalEvent(MusicDeviceGroupID inGroupID, UInt32 inEventType, UInt32 inOffsetSampleFrame) { - + if (InRenderThread ()) { SynthGroupElement *group = GetElForGroupID(inGroupID); if (!group) return kAudioUnitErr_InvalidElement; - + switch (inEventType) { case SynthEvent::kEventType_SustainOn : @@ -532,7 +532,7 @@ OSStatus AUInstrumentBase::SendPedalEvent(MusicDeviceGroupID inGroupID, UInt32 i if (!event) return -1; // queue full event->Set(inEventType, inGroupID, 0, 0, NULL); - + mEventQueue.AdvanceWritePtr(); } return noErr; @@ -576,7 +576,7 @@ OSStatus AUInstrumentBase::HandleControlChange( UInt8 inChannel, } return noErr; } - + OSStatus AUInstrumentBase::HandlePitchWheel( UInt8 inChannel, UInt8 inPitch1, // LSB UInt8 inPitch2, // MSB @@ -592,7 +592,7 @@ OSStatus AUInstrumentBase::HandlePitchWheel( UInt8 inChannel, return kAudioUnitErr_InvalidElement; } - + OSStatus AUInstrumentBase::HandleChannelPressure(UInt8 inChannel, UInt8 inValue, UInt32 inStartFrame) @@ -647,13 +647,13 @@ OSStatus AUInstrumentBase::HandleResetAllControllers( UInt8 inChannel) return SendPedalEvent (inChannel, SynthEvent::kEventType_ResetAllControllers, 0); } - + OSStatus AUInstrumentBase::HandleAllNotesOff( UInt8 inChannel) { return SendPedalEvent (inChannel, SynthEvent::kEventType_AllNotesOff, 0); } - + OSStatus AUInstrumentBase::HandleAllSoundOff( UInt8 inChannel) { return SendPedalEvent (inChannel, SynthEvent::kEventType_AllSoundOff, 0); @@ -670,7 +670,7 @@ SynthNote* AUInstrumentBase::GetAFreeNote(UInt32 inFrame) mFreeNotes.RemoveNote(note); return note; } - + return VoiceStealing(inFrame, true); } @@ -724,13 +724,13 @@ SynthNote* AUInstrumentBase::VoiceStealing(UInt32 inFrame, bool inKillIt) #if DEBUG_PRINT_NOTE printf("no notes to steal????\n"); #endif - return NULL; // It should be impossible to get here. It means there were no notes to kill in any state. + return NULL; // It should be impossible to get here. It means there were no notes to kill in any state. } //////////////////////////////////////////////////////////////////////////////////////////////////////////// AUMonotimbralInstrumentBase::AUMonotimbralInstrumentBase( - AudioComponentInstance inInstance, + AudioComponentInstance inInstance, UInt32 numInputs, UInt32 numOutputs, UInt32 numGroups, @@ -739,28 +739,28 @@ AUMonotimbralInstrumentBase::AUMonotimbralInstrumentBase( { } -OSStatus AUMonotimbralInstrumentBase::RealTimeStartNote( - SynthGroupElement *inGroup, - NoteInstanceID inNoteInstanceID, - UInt32 inOffsetSampleFrame, +OSStatus AUMonotimbralInstrumentBase::RealTimeStartNote( + SynthGroupElement *inGroup, + NoteInstanceID inNoteInstanceID, + UInt32 inOffsetSampleFrame, const MusicDeviceNoteParams &inParams) { #if DEBUG_PRINT_RENDER printf("AUMonotimbralInstrumentBase::RealTimeStartNote %d\n", inNoteInstanceID); #endif - if (NumActiveNotes() + 1 > MaxActiveNotes()) + if (NumActiveNotes() + 1 > MaxActiveNotes()) { VoiceStealing(inOffsetSampleFrame, false); } SynthNote *note = GetAFreeNote(inOffsetSampleFrame); if (!note) return -1; - + SynthPartElement *part = GetPartElement (0); // Only one part for monotimbral - + IncNumActiveNotes(); inGroup->NoteOn(note, part, inNoteInstanceID, inOffsetSampleFrame, inParams); - + return noErr; } @@ -774,8 +774,8 @@ OSStatus AUMultitimbralInstrumentBase::GetPropertyInfo(AudioUnitPropertyID inI Boolean & outWritable) { OSStatus result = noErr; - - switch (inID) + + switch (inID) { #if !TARGET_OS_IPHONE case kMusicDeviceProperty_PartGroup: @@ -797,7 +797,7 @@ OSStatus AUMultitimbralInstrumentBase::GetProperty( AudioUnitPropertyID inID, { OSStatus result = noErr; - switch (inID) + switch (inID) { #if !TARGET_OS_IPHONE case kMusicDeviceProperty_PartGroup: @@ -809,7 +809,7 @@ OSStatus AUMultitimbralInstrumentBase::GetProperty( AudioUnitPropertyID inID, default: result = AUInstrumentBase::GetProperty (inID, inScope, inElement, outData); } - + return result; } @@ -823,7 +823,7 @@ OSStatus AUMultitimbralInstrumentBase::SetProperty( AudioUnitPropertyID in { OSStatus result = noErr; - switch (inID) + switch (inID) { #if !TARGET_OS_IPHONE case kMusicDeviceProperty_PartGroup: @@ -835,7 +835,7 @@ OSStatus AUMultitimbralInstrumentBase::SetProperty( AudioUnitPropertyID in default: result = MusicDeviceBase::SetProperty (inID, inScope, inElement, inData, inDataSize); } - + return result; } |