Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AudioToolbox] Make P/Invokes in MusicTrack.cs have blittable signatures. #19678

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions src/AudioToolbox/MusicTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand All @@ -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));
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
19 changes: 19 additions & 0 deletions tests/monotouch-test/AudioToolbox/MusicTrackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading