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

Release/v1.3.0 #3

Merged
merged 2 commits into from
Sep 6, 2023
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
18 changes: 9 additions & 9 deletions RtMidi.Net/Clients/MidiInputClient.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Diagnostics;
using RtMidi.Net.Enums;
using RtMidi.Net.Events;
using RtMidi.Net.InteropServices;
using System.Diagnostics;

namespace RtMidi.Net.Clients;

public class MidiInputClient : MidiClient

Check warning on line 8 in RtMidi.Net/Clients/MidiInputClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'MidiInputClient'

Check warning on line 8 in RtMidi.Net/Clients/MidiInputClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'MidiInputClient'
{
private readonly RtMidiIn _rtMidiInClient;
private bool _ignoreSysexMessages = true;
private bool _ignoreTimeMessages = true;
private bool _ignoreSenseMessages = true;

public bool IgnoreSysexMessages

Check warning on line 15 in RtMidi.Net/Clients/MidiInputClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'MidiInputClient.IgnoreSysexMessages'

Check warning on line 15 in RtMidi.Net/Clients/MidiInputClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'MidiInputClient.IgnoreSysexMessages'
{
get => _ignoreSysexMessages;
set
Expand All @@ -22,7 +22,7 @@
}
}

public bool IgnoreTimeMessages

Check warning on line 25 in RtMidi.Net/Clients/MidiInputClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'MidiInputClient.IgnoreTimeMessages'

Check warning on line 25 in RtMidi.Net/Clients/MidiInputClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'MidiInputClient.IgnoreTimeMessages'
{
get => _ignoreTimeMessages;
set
Expand All @@ -46,7 +46,7 @@

public MidiInputClient(MidiDeviceInfo deviceInfo) : base(deviceInfo, new RtMidiIn())
{
_rtMidiInClient = (RtMidiIn) RtMidiClient;
_rtMidiInClient = (RtMidiIn)RtMidiClient;
}

public void ActivateMessageReceivedEvent()
Expand All @@ -66,8 +66,8 @@

private void InternalMessageReceived(double timestamp, IntPtr messagePtr, UIntPtr messageSize, IntPtr userDataPtr)
{
var messageData = new byte [(int) messageSize];
System.Runtime.InteropServices.Marshal.Copy(messagePtr, messageData, 0, (int) messageSize);
var messageData = new byte[(int)messageSize];
System.Runtime.InteropServices.Marshal.Copy(messagePtr, messageData, 0, (int)messageSize);
var message = ConvertMessage(messageData);
var midiEventArgs = new MidiMessageReceivedEventArgs(message, TimeSpan.FromSeconds(timestamp));
OnMessageReceived?.Invoke(this, midiEventArgs);
Expand All @@ -93,7 +93,7 @@
{
Stopwatch stopwatch = new();
byte[] messageData;

stopwatch.Start();
do
{
Expand All @@ -113,10 +113,10 @@
{
MidiMessageType type;

if (message[0] is >= (byte) MidiMessageType.NoteOff and < (byte) MidiMessageType.SystemExclusive)
if (message[0] is >= (byte)MidiMessageType.NoteOff and < (byte)MidiMessageType.SystemExclusive)
{
var channel = (MidiChannel) (0b_0000_1111 & message[0]);
type = (MidiMessageType) (0b_1111_0000 & message[0]);
var channel = (MidiChannel)(0b_0000_1111 & message[0]);
type = (MidiMessageType)(0b_1111_0000 & message[0]);

switch (type)
{
Expand All @@ -143,7 +143,7 @@
return new MidiMessageUnknown(message.ToArray());
}

type = (MidiMessageType) message[0];
type = (MidiMessageType)message[0];
switch (type)
{
case MidiMessageType.SystemExclusive:
Expand Down
8 changes: 4 additions & 4 deletions RtMidi.Net/Clients/MidiOutputClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MidiOutputClient : MidiClient

public MidiOutputClient(MidiDeviceInfo deviceInfo) : base(deviceInfo, new RtMidiOut())
{
_rtMidiOutClient = (RtMidiOut) RtMidiClient;
_rtMidiOutClient = (RtMidiOut)RtMidiClient;
}

public void SendMessage(byte[] message)
Expand Down Expand Up @@ -64,7 +64,7 @@ private static byte[] ConvertMessage(MidiMessage message)
},
MidiMessageType.SystemExclusive when message is MidiMessageSystemExclusive(var data, _) => data,
//TODO Create Message for TimeCodeQuarterFrame
MidiMessageType.TimeCodeQuarterFrame when message is MidiMessageUnknown (var data, _) => data,
MidiMessageType.TimeCodeQuarterFrame when message is MidiMessageUnknown(var data, _) => data,
MidiMessageType.SongPositionPointer when message is MidiMessageSongPositionPointer songPosPointer => new[]
{
(byte) songPosPointer.Type,
Expand Down Expand Up @@ -97,12 +97,12 @@ private static byte[] ConvertMessage(MidiMessage message)

byte ByteFrom(MidiMessageType messageType, MidiChannel channel)
{
return (byte) ((byte) messageType | (byte) channel);
return (byte)((byte)messageType | (byte)channel);
}

byte[] DefaultMessage(MidiMessage midiMessage)
{
return new[] {(byte) midiMessage.Type};
return new[] { (byte)midiMessage.Type };
}
}
}
4 changes: 3 additions & 1 deletion RtMidi.Net/Enums/MidiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum MidiApi : byte
LinuxAlsa,
UnixJack,
WindowsMultimediaMidi,
WindowsKernelStreaming,
RtMidiDummy,
WebMidi,
WindowsUwp,
Android,
}
2 changes: 1 addition & 1 deletion RtMidi.Net/Enums/MidiMessageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace RtMidi.Net.Enums;
public enum MidiMessageType : byte
{
Unknown = 0,

NoteOff = 0b_1000_0000,
NoteOn = 0b_1001_0000,
PolyphonicKeyPressure = 0b_1010_0000,
Expand Down
2 changes: 1 addition & 1 deletion RtMidi.Net/Enums/MusicNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum MusicNote : byte
A = 9,
ASharp = 10,
B = 11,

Do = C,
DoSharp = CSharp,
Re = D,
Expand Down
19 changes: 15 additions & 4 deletions RtMidi.Net/InteropServices/RtMidiBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Runtime.InteropServices;
using RtMidi.Net.Enums;
using System.Runtime.InteropServices;

namespace RtMidi.Net.InteropServices;

Expand All @@ -19,7 +19,7 @@ internal abstract class RtMidiBase : IDisposable
/// </remarks>
/// <returns>Returns true if a port is open and false if not.</returns>
public bool IsPortOpen { get; private set; }

protected RtMidiBase(IntPtr rtMidiPtr)
{
RtMidiPtr = rtMidiPtr;
Expand Down Expand Up @@ -97,7 +97,7 @@ public string GetPortName(uint portNumber, uint? nameSize = null)
bufferNameSize = nameSize.Value;
}

messagePtr = Marshal.AllocHGlobal((int) bufferNameSize);
messagePtr = Marshal.AllocHGlobal((int)bufferNameSize);
try
{
resultInterop = RtMidiInterop.rtmidi_get_port_name(RtMidiPtr, portNumber, messagePtr, ref bufferNameSize);
Expand Down Expand Up @@ -159,7 +159,7 @@ public static IReadOnlyCollection<MidiApi> GetCompiledApi()
var unmanagedPointer = Marshal.AllocHGlobal(apis.Length);
Marshal.Copy(apis, 0, unmanagedPointer, apis.Length);
var result = RtMidiInterop.rtmidi_get_compiled_api(unmanagedPointer, sizeof(MidiApi));
apis = new byte [result];
apis = new byte[result];
Marshal.Copy(unmanagedPointer, apis, 0, result);
var apisResult = apis.Cast<MidiApi>().ToList();
Marshal.FreeHGlobal(unmanagedPointer);
Expand Down Expand Up @@ -203,6 +203,17 @@ public static string GetApiDisplayName(MidiApi api)
return name ?? string.Empty;
}

/// <summary>
/// Return the version of the RtMidi library.
/// </summary>
/// <returns> The version of the RtMidi library </returns>
public static string GetRtMidiVersion()
{
var ptr = RtMidiInterop.rtmidi_get_version();
var name = Marshal.PtrToStringUTF8(ptr);
return name ?? string.Empty;
}

/// <summary>
/// Return the compiled MIDI API having the given name.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion RtMidi.Net/InteropServices/RtMidiCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
namespace RtMidi.Net.InteropServices;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void RtMidiCallback (double timestamp, IntPtr message, UIntPtr size, IntPtr userData);
internal delegate void RtMidiCallback(double timestamp, IntPtr message, UIntPtr size, IntPtr userData);
6 changes: 3 additions & 3 deletions RtMidi.Net/InteropServices/RtMidiIn.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Runtime.InteropServices;
using RtMidi.Net.Enums;
using System.Runtime.InteropServices;

namespace RtMidi.Net.InteropServices;

Expand Down Expand Up @@ -121,12 +121,12 @@ public void IgnoreTypes(bool midiSysex = true, bool midiTime = true, bool midiSe
{
var size = 1024;
var messagePtr = Marshal.AllocHGlobal(size);

var timestamp = RtMidiInterop.rtmidi_in_get_message(RtMidiPtr, messagePtr, ref size);
var message = new byte[size];
Marshal.Copy(messagePtr, message, 0, size);
Marshal.FreeHGlobal(messagePtr);

return (message, timestamp);
}

Expand Down
Loading
Loading