diff --git a/src/AudioToolbox/MusicTrack.cs b/src/AudioToolbox/MusicTrack.cs index 6ead84347b70..6c2fff14d4b3 100644 --- a/src/AudioToolbox/MusicTrack.cs +++ b/src/AudioToolbox/MusicTrack.cs @@ -278,12 +278,15 @@ protected override void Dispose (bool disposing) } [DllImport (Constants.AudioToolboxLibrary)] - extern static /* OSStatus */ MusicPlayerStatus MusicTrackGetSequence (/* MusicTrack */ IntPtr inTrack, /* MusicSequence* */ out IntPtr outSequence); + unsafe extern static /* OSStatus */ MusicPlayerStatus MusicTrackGetSequence (/* MusicTrack */ IntPtr inTrack, /* MusicSequence* */ IntPtr* outSequence); public MusicSequence? Sequence { get { - if (MusicTrackGetSequence (Handle, out var seqHandle) == MusicPlayerStatus.Success) - return MusicSequence.Lookup (seqHandle); + IntPtr seqHandle; + unsafe { + if (MusicTrackGetSequence (Handle, &seqHandle) == MusicPlayerStatus.Success) + return MusicSequence.Lookup (seqHandle); + } return null; } } @@ -298,11 +301,15 @@ public MusicPlayerStatus SetDestMidiEndpoint (MidiEndpoint endpoint) } [DllImport (Constants.AudioToolboxLibrary)] - extern static /* OSStatus */ MusicPlayerStatus MusicTrackGetDestMIDIEndpoint (/* MusicTrack */ IntPtr inTrack, out MidiEndpointRef outEndpoint); + unsafe extern static /* OSStatus */ MusicPlayerStatus MusicTrackGetDestMIDIEndpoint (/* MusicTrack */ IntPtr inTrack, MidiEndpointRef* outEndpoint); public MusicPlayerStatus GetDestMidiEndpoint (out MidiEndpoint? outEndpoint) { - var result = MusicTrackGetDestMIDIEndpoint (Handle, out var midiHandle); + MidiEndpointRef midiHandle; + MusicPlayerStatus result; + unsafe { + result = MusicTrackGetDestMIDIEndpoint (Handle, &midiHandle); + } outEndpoint = (result == MusicPlayerStatus.Success)? new MidiEndpoint (midiHandle): null; return result; } @@ -317,16 +324,16 @@ public MusicPlayerStatus SetDestNode (int node) } [DllImport (Constants.AudioToolboxLibrary)] - extern unsafe static /* OSStatus */ MusicPlayerStatus MusicTrackSetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, void* inData, /* UInt32 */ int inLength); + extern unsafe static /* OSStatus */ MusicPlayerStatus MusicTrackSetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, byte* inData, /* UInt32 */ int inLength); [DllImport (Constants.AudioToolboxLibrary)] - extern static /* OSStatus */ MusicPlayerStatus MusicTrackSetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, ref double inData, /* UInt32 */ int inLength); + unsafe extern static /* OSStatus */ MusicPlayerStatus MusicTrackSetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, double* inData, /* UInt32 */ int inLength); [DllImport (Constants.AudioToolboxLibrary)] - extern unsafe static /* OSStatus */ MusicPlayerStatus MusicTrackGetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, void* outData, /* UInt32* */ ref int ioLength); + extern unsafe static /* OSStatus */ MusicPlayerStatus MusicTrackGetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, byte* outData, /* UInt32* */ int* ioLength); [DllImport (Constants.AudioToolboxLibrary)] - extern static /* OSStatus */ MusicPlayerStatus MusicTrackGetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, ref double outData, /* UInt32* */ ref int ioLength); + unsafe extern static /* OSStatus */ MusicPlayerStatus MusicTrackGetProperty (/* MusicTrack */ IntPtr inTrack, /* UInt32 */ SequenceTrackProperty propertyId, double* outData, /* UInt32* */ int* ioLength); // internal use only - it's a UInt32 in the API enum SequenceTrackProperty { @@ -344,13 +351,14 @@ public bool MuteStatus { byte val; unsafe { int len = 1; - MusicTrackGetProperty (Handle, SequenceTrackProperty.MuteStatus, &val, ref len); + MusicTrackGetProperty (Handle, SequenceTrackProperty.MuteStatus, &val, &len); return val != 0; } } set { unsafe { - MusicTrackSetProperty (Handle, SequenceTrackProperty.MuteStatus, &value, 1); + var val = value ? (byte) 1 : (byte) 0; + MusicTrackSetProperty (Handle, SequenceTrackProperty.MuteStatus, &val, 1); } } } @@ -360,13 +368,14 @@ public bool SoloStatus { byte val; unsafe { int len = 1; - MusicTrackGetProperty (Handle, SequenceTrackProperty.SoloStatus, &val, ref len); + MusicTrackGetProperty (Handle, SequenceTrackProperty.SoloStatus, &val, &len); return val != 0; } } set { unsafe { - MusicTrackSetProperty (Handle, SequenceTrackProperty.SoloStatus, &value, 1); + var val = value ? (byte) 1 : (byte) 0; + MusicTrackSetProperty (Handle, SequenceTrackProperty.SoloStatus, &val, 1); } } } @@ -375,11 +384,15 @@ public double TrackLength { get { double value = 0; int len = sizeof (double); - MusicTrackGetProperty (Handle, SequenceTrackProperty.TrackLength, ref value, ref len); + unsafe { + MusicTrackGetProperty (Handle, SequenceTrackProperty.TrackLength, &value, &len); + } return value; } set { - MusicTrackSetProperty (Handle, SequenceTrackProperty.TrackLength, ref value, sizeof (double)); + unsafe { + MusicTrackSetProperty (Handle, SequenceTrackProperty.TrackLength, &value, sizeof (double)); + } } } diff --git a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs index 25cee30bd483..e74ea834aafb 100644 --- a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs +++ b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs @@ -99,11 +99,6 @@ public partial class BlittablePInvokes { "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicSequence::MusicSequenceGetTrackIndex(System.IntPtr,System.IntPtr,System.Int32&)", "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicSequence::MusicSequenceNewTrack(System.IntPtr,System.IntPtr&)", "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicSequence::NewMusicSequence(System.IntPtr&)", - "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicTrack::MusicTrackGetDestMIDIEndpoint(System.IntPtr,System.Int32&)", - "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicTrack::MusicTrackGetProperty(System.IntPtr,AudioToolbox.MusicTrack/SequenceTrackProperty,System.Double&,System.Int32&)", - "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicTrack::MusicTrackGetProperty(System.IntPtr,AudioToolbox.MusicTrack/SequenceTrackProperty,System.Void*,System.Int32&)", - "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicTrack::MusicTrackGetSequence(System.IntPtr,System.IntPtr&)", - "AudioToolbox.MusicPlayerStatus AudioToolbox.MusicTrack::MusicTrackSetProperty(System.IntPtr,AudioToolbox.MusicTrack/SequenceTrackProperty,System.Double&,System.Int32)", "AudioUnit.AudioComponentDescription ObjCRuntime.Messaging::AudioComponentDescription_objc_msgSend(System.IntPtr,System.IntPtr)", "AudioUnit.AudioComponentDescription ObjCRuntime.Messaging::AudioComponentDescription_objc_msgSendSuper(System.IntPtr,System.IntPtr)", "AudioUnit.AudioComponentStatus AudioUnit.AudioUnit::AudioOutputUnitPublish(AudioUnit.AudioComponentDescription,System.IntPtr,System.UInt32,System.IntPtr)", diff --git a/tests/monotouch-test/AudioToolbox/MusicTrackTest.cs b/tests/monotouch-test/AudioToolbox/MusicTrackTest.cs index 17a5f195003a..2ab316fe4602 100644 --- a/tests/monotouch-test/AudioToolbox/MusicTrackTest.cs +++ b/tests/monotouch-test/AudioToolbox/MusicTrackTest.cs @@ -44,6 +44,25 @@ public void Defaults () { Assert.That (track.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle"); Assert.That (track.Sequence, Is.Not.Null, "Sequence"); + + Assert.IsFalse (track.MuteStatus, "MuteStatus"); + track.MuteStatus = true; + Assert.IsTrue (track.MuteStatus, "MuteStatus B"); + track.MuteStatus = false; + Assert.IsFalse (track.MuteStatus, "MuteStatus C"); + + Assert.IsFalse (track.SoloStatus, "SoloStatus"); + track.SoloStatus = true; + Assert.IsTrue (track.SoloStatus, "SoloStatus B"); + track.SoloStatus = false; + Assert.IsFalse (track.SoloStatus, "SoloStatus C"); + + Assert.AreEqual (0.0f, track.TrackLength, "TrackLength"); + var originalTrackLength = track.TrackLength; + track.TrackLength = 1.32f; + Assert.AreEqual (1.32f, track.TrackLength, "TrackLength B"); + track.TrackLength = originalTrackLength; + Assert.AreEqual (0.0f, track.TrackLength, "TrackLength C"); } [Test]