Skip to content

Commit

Permalink
Notify when CC/SysEx is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
KaleidonKep99 committed Feb 28, 2025
1 parent 1d82a5c commit 05edcf5
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 63 deletions.
2 changes: 1 addition & 1 deletion OmniConverter/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.0.0.77</VersionPrefix>
<VersionPrefix>1.0.0.83</VersionPrefix>
</PropertyGroup>
</Project>
55 changes: 24 additions & 31 deletions OmniConverter/Extensions/Audio/Renderers/BASSRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,6 @@ public class BASSEngine : AudioEngine

public BASSEngine(Settings settings) : base(settings, false)
{
/*
-+++------.
-++###+#++++++++++#+++-
++##+-.. -#+- .++#++
-+#+. .++. .+#+-
+#+. .+++
++#+++. .+++
##++++####+-. -#+-
+#- -+++##++- .+++-
.+- ++. .##+
. +- +#+ +##.
++. ++++++++#+ KHANG!!! .+++
-++#+++++-. -++
++- +
-++++++++++++++++.
.------------#+
-++.
+#- --
+#+#+ .++##+
-+#+- ++. +++. .#+.
+++..-+#+- +#- -++#+#.
++++#+++++ -+++#+-.
. .#+ -+-
++-
-++.
*/

if (Bass.Init(Bass.NoSoundDevice, _waveFormat.SampleRate, DeviceInitFlags.Default))
{
_bassArray = InitializeSoundFonts();
Expand Down Expand Up @@ -297,13 +270,16 @@ public override bool SendCustomCC(int channel, short reverb, short chorus)
public override void SendEvent(byte[] data)
{
var status = data[0];

var isSysEx = (EventType)status == EventType.SystemExclusive;
var type = (EventType)(status & 0xF0);
var param1 = data.Length >= 2 ? data[1] : 0;
var param2 = data.Length >= 3 ? data[2] : 0;

int eventParams;
var eventType = MidiEventType.Note;

switch ((EventType)(status & 0xF0))
switch (type)
{
case EventType.NoteOn:
eventParams = param2 << 8 | param1;
Expand Down Expand Up @@ -334,11 +310,28 @@ public override void SendEvent(byte[] data)
break;

default:
BassMidi.StreamEvents(_streamHandle, MidiEventsMode.Raw | MidiEventsMode.NoRunningStatus, data, data.Length);
var ret = BassMidi.StreamEvents(_streamHandle, MidiEventsMode.Raw | MidiEventsMode.NoRunningStatus, data, data.Length);

if (ret == -1 || (isSysEx && ret < 1))
Debug.PrintToConsole(Debug.LogType.Error, $"Unsupported {(isSysEx ? "SysEx" : "data")}! >> {BitConverter.ToString(data).Replace("-", "")}");

return;
}

BassMidi.StreamEvent(_streamHandle, status & 0xF, eventType, eventParams);
var success = BassMidi.StreamEvent(_streamHandle, status & 0xF, eventType, eventParams);

if (!success)
{
switch (type)
{
case EventType.Controller:
Debug.PrintToConsole(Debug.LogType.Error, $"Unsupported CC! >> {(ControllerType)param1}");
break;

default:
break;
}
}
}

public override void RefreshInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,12 @@ public override void SendEvent(byte[] data)
return;

var status = data[0];
var type = (EventType)(status & 0xF0);
var chan = status & 0xF;
var param1 = data[1];
var param2 = data.Length >= 3 ? data[2] : (byte)0;

switch ((EventType)(status & 0xF0))
switch (type)
{
case EventType.NoteOn:
if (param1 == 0)
Expand All @@ -240,7 +241,9 @@ public override void SendEvent(byte[] data)
return;

case EventType.Controller:
handle.CC(chan, param1, param2);
if (!handle.CC(chan, param1, param2))
Debug.PrintToConsole(Debug.LogType.Error, $"Unsupported CC! >> {(ControllerType)param1}");

return;

case EventType.PitchBend:
Expand Down
13 changes: 4 additions & 9 deletions OmniConverter/Extensions/Audio/Renderers/XSynthRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class XSynth
{
private const string XSynthLib = "xsynth";

public const uint APIVersion = 0x300;

public enum AudioEvent : ushort
{
NoteOn = 0,
Expand Down Expand Up @@ -164,7 +162,8 @@ public struct SoundfontOptions
[DllImport(XSynthLib, EntryPoint = "XSynth_Soundfont_Remove", CallingConvention = CallingConvention.Cdecl)]
public static extern void Soundfont_Remove(XSynth_Soundfont id);

public static Version Version => MiscFunctions.ConvertIntToVersion((int)GetVersionInt());
public static Version LibraryVersion => MiscFunctions.ConvertIntToVersion((int)GetVersionInt());
public static Version APIVersion => new Version(0, 3, 0 ,0);
}

public class XSynthEngine : AudioEngine
Expand All @@ -179,12 +178,8 @@ public class XSynthEngine : AudioEngine

public unsafe XSynthEngine(Settings settings) : base(settings, false)
{
var libraryVersion = GetVersionInt();
if (libraryVersion >> 8 != APIVersion >> 8)
{
var neededVer = MiscFunctions.ConvertIntToVersion((int)APIVersion);
throw new Exception($"Unsupported version of XSynth loaded. Please use version {neededVer.Major}.{neededVer.Minor}.x");
}
if (LibraryVersion.Major != APIVersion.Major)
throw new Exception($"Unsupported version of XSynth loaded. Please use version {APIVersion.Major}.{APIVersion.Minor}.x");

Debug.PrintToConsole(Debug.LogType.Message, $"Preparing XSynth...");

Expand Down
13 changes: 1 addition & 12 deletions OmniConverter/Forms/InfoWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@
</Grid>
<Separator />
<TextBlock Grid.Row="0" Name="CopyrightText">
Copyright Ⓒ 2024 Keppy's Software and Arduano
<LineBreak/>
Free MIDI converter for Microsoft Windows, Linux and macOS
<LineBreak/>
<LineBreak/>
This software is open-source.
<LineBreak/>
Redistribution and use of this code or any derivative works are permitted
<LineBreak/>
provided that specific conditions are met.
<LineBreak/>
Click the blue note button to see the license.
EMPTY
</TextBlock>
</StackPanel>
<Grid Grid.Row="1" RowDefinitions="1*, 32">
Expand Down
31 changes: 24 additions & 7 deletions OmniConverter/Forms/InfoWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
Expand All @@ -12,23 +12,38 @@ namespace OmniConverter;

public partial class InfoWindow : Window
{
private string BleBleBleBlaBlaBla =
"Copyright Ⓒ DATE_YEAR Keppy's Software & Black MIDI Devs\n" +
"Free MIDI converter for 64-bit Windows, Linux and macOS\n\n" +
"This software is open-source.\n" +
"Redistribution and use of this code or any derivative works\n" +
"are permitted provided that specific conditions are met.\n" +
"Click the blue note button to see the license.";

public InfoWindow()
{
InitializeComponent();

Loaded += FillUpInfo;
}

private void FillUpInfo(object? sender, RoutedEventArgs e)
{
var year = DateTime.Now.Year.LimitToRange(2024, 9999);

var pp = Environment.ProcessPath;
var cv = Assembly.GetExecutingAssembly().GetName().Version;
bool isDev = false;
var isDev = false;

var dummy = new Version(0, 0, 0, 0);
Version? bassVer = dummy;
Version? bmidiVer = dummy;
Version? xsynthVer = dummy;
Version convVer = cv != null ? cv : dummy;
var bassVer = dummy;
var bmidiVer = dummy;
var xsynthVer = dummy;
var convVer = cv != null ? cv : dummy;

try { bassVer = Bass.Version; } catch { }
try { bmidiVer = BassMidi.Version; } catch { }
try { xsynthVer = XSynth.Version; } catch { }
try { xsynthVer = XSynth.LibraryVersion; } catch { }

if (pp != null)
{
Expand All @@ -46,6 +61,8 @@ public InfoWindow()
BMIDIVersion.Content = MiscFunctions.ReturnAssemblyVersion(string.Empty, "Rev. ", [bmidiVer.Major, bmidiVer.Minor, bmidiVer.Build, bmidiVer.Revision]);
XSynthVersion.Content = MiscFunctions.ReturnAssemblyVersion(string.Empty, "Rev. ", [xsynthVer.Major, xsynthVer.Minor, xsynthVer.Build, xsynthVer.Revision]);

CopyrightText.Text = BleBleBleBlaBlaBla.Replace("DATE_YEAR", $"{year}");

SetBranchColor();
}

Expand Down
2 changes: 1 addition & 1 deletion nfluidsynth

0 comments on commit 05edcf5

Please sign in to comment.