Re: AUMIDISynth program change messages not working?
Re: AUMIDISynth program change messages not working?
- Subject: Re: AUMIDISynth program change messages not working?
- From: Archagon <email@hidden>
- Date: Wed, 13 Jan 2016 21:12:34 -0800
Thank you! This is good to know.
I have a couple more questions regarding AUMIDISynth:
1. Is there any way to get the MIDI key range of a patch? In my app,
before I discovered AUMIDISynth, I was using a bunch of AUSamplers (1
per channel). Here, I could simply get the global
kAudioUnitProperty_ClassInfo property for each sampler and then find
the "min key" and "max key" properties in the resulting dictionary. I
tried doing the same for AUMIDISynth, but unfortunately the resulting
dictionary is not the same as the AUSampler dictionary and does not
have those keys. The headers imply that you might be able to use
kAudioUnitScope_Part for multitimbral instruments, but so far, all
I've been getting is error -10866.
2. Is there a way to have more than 16 "channels" per AUMIDISynth? (I
realize it wouldn't be GM-compliant, but I can route around it.) My
app requires a very large number of individual voices, each receiving
their own MIDI channel commands, and it would be more efficient if I
could share the samples that AUMIDISynth preloads for all my channels
instead of creating a bunch of different AUMIDISynths (each with their
own preloaded samples).
Thank you,
-Alexei
On Tue, Jan 12, 2016 at 9:56 AM, Douglas Scott <email@hidden> wrote:
> Typo there: that should read "responds to program changes as requests to switch”.
>
> -DS
>
>> On Jan 12, 2016, at 9:54 AM, Douglas Scott <email@hidden> wrote:
>>
>> Yes. When “enable preload” is on, sending a program change tells the AU to load the resources for the particular patch from file into memory. The idea is that you do ALL of those “preload” requests up front, before doing anything else. Once “enable preload” is off again, the AU responds like any GM synth does, and responds to program changes as a request switch to the requested (and already pre-loaded) patch during MIDI playback.
>>
>> -DS
>>
>>> On Jan 11, 2016, at 12:47 PM, Archagon <email@hidden> wrote:
>>>
>>> Hi Douglas, thank you for the help. I had tried playing with
>>> kAUMIDISynthProperty_EnablePreload before sending my original e-mail,
>>> but I didn't realize I had to disable it before sending further MIDI
>>> messages. ("Playback" seemed like it was referring to MusicSequence,
>>> not real-time MIDI note-on messages.)
>>>
>>> This time, I had trouble getting it to work, but then I realized I had
>>> to send the program change message a second time after enabling
>>> preload for my chosen instrument:
>>>
>>> UInt32 instrument = arc4random_uniform(100);
>>>
>>> UInt32 enabled = 1;
>>> AudioUnitSetProperty(self.samplerUnit,
>>> kAUMIDISynthProperty_EnablePreload, kAudioUnitScope_Global, 0,
>>> &enabled, sizeof(enabled));
>>>
>>> UInt32 command = 0xC0 | 0;
>>> MusicDeviceMIDIEvent(self.samplerUnit, command, instrument, 0, 0);
>>>
>>> enabled = 0;
>>> AudioUnitSetProperty(self.samplerUnit,
>>> kAUMIDISynthProperty_EnablePreload, kAudioUnitScope_Global, 0,
>>> &enabled, sizeof(enabled));
>>>
>>> // sending the program change message a second time!
>>> MusicDeviceMIDIEvent(self.samplerUnit, command, instrument, 0, 0);
>>>
>>> UInt32 noteNum = kMidNote;
>>> UInt32 onVelocity = 127;
>>> UInt32 noteCommand = kMIDIMessage_NoteOn << 4 | 0;
>>> MusicDeviceMIDIEvent(self.samplerUnit, noteCommand, noteNum, onVelocity, 0);
>>>
>>> This code finally let me switch the instrument on device. Without the
>>> second program change message, the synth was stuck on the piano patch.
>>> Is this the correct approach?
>>>
>>> Thank you,
>>> -Alexei
>>>
>>> On Mon, Jan 11, 2016 at 10:14 AM, Douglas Scott <email@hidden> wrote:
>>>> From AudioUnitProperties.h:
>>>>
>>>> /*!
>>>> @enum Apple AUMIDISynth Property IDs
>>>> @abstract The collection of property IDs for the Apple Midi Synth audio
>>>> unit.
>>>>
>>>>
>>>>
>>>> @discussion The AUMIDISynth audio unit lets a client create fully
>>>> GM-compatible Midi Synth.
>>>>
>>>>
>>>>
>>>> @constant kAUMIDISynthProperty_EnablePreload
>>>> @discussion Scope: Global
>>>> Value Type: UInt32
>>>> Access: Write
>>>>
>>>>
>>>>
>>>> Setting this property to 1 puts the MIDISynth in a mode where it will
>>>> attempt to load
>>>> instruments from the bank or file when it receives a program change
>>>> message. This
>>>> is used internally by the MusicSequence. It should only be used prior to
>>>> MIDI playback,
>>>> and must be set back to 0 before attempting to start playback.
>>>> */
>>>>
>>>> CF_ENUM(AudioUnitPropertyID) {
>>>> kAUMIDISynthProperty_EnablePreload = 4119
>>>> };
>>>>
>>>> This is needed on the device because we do not have the spare memory to load
>>>> every instrument from a bank in advance. Set this property to 1, send your
>>>> program changes (looks like you will need to send a message for ALL of them
>>>> if you are randomly choosing one later), then set the property to 0, then
>>>> start playback.
>>>>
>>>> -DS
>>>>
>>>> On Jan 9, 2016, at 8:00 PM, Archagon <email@hidden> wrote:
>>>>
>>>> Hello,
>>>>
>>>> I can't figure out how to make the AUMIDISynth MusicDevice
>>>> (kAudioUnitType_MusicDevice, kAudioUnitSubType_MIDISynth) change its
>>>> instrument on iOS. In the simulator, sending the following message...
>>>>
>>>> UInt32 command = 0xC0 | 0;
>>>> UInt32 instrument = arc4random_uniform(100);
>>>> MusicDeviceMIDIEvent(self.samplerUnit, command, instrument, 0, 0);
>>>>
>>>> ...works fine. On device, however, the synth just goes mute after
>>>> receiving the message. (The first instrument in the soundfont —
>>>> usually piano — does load correctly, however.) Is this a bug? If so,
>>>> is there any way to work around it?
>>>>
>>>> Here's a simple test case based on the LoadPreset demo:
>>>> https://github.com/archagon/ios-midisynth-program-change-bug-demo
>>>> You can tap the middle button to change to a random instrument.
>>>>
>>>> Thank you,
>>>> -Alexei
>>>>
>>>> _______________________________________________
>>>> Do not post admin requests to the list. They will be ignored.
>>>> Coreaudio-api mailing list (email@hidden)
>>>> Help/Unsubscribe/Update your Subscription:
>>>>
>>>> This email sent to email@hidden
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Coreaudio-api mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden