Skip to content

Commit

Permalink
feat: #11 creating Windows view of an alternative.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroxpepe committed Feb 28, 2021
1 parent 4dcc2f2 commit d7c8046
Show file tree
Hide file tree
Showing 21 changed files with 4,153 additions and 26 deletions.
9 changes: 6 additions & 3 deletions MidiPlayer.Droid/MidiPlayer.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,16 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NLog">
<Version>4.7.7</Version>
<Version>4.7.8</Version>
</PackageReference>
<PackageReference Include="NLog.Config">
<Version>4.7.7</Version>
<Version>4.7.8</Version>
</PackageReference>
<PackageReference Include="NLog.Extensions.Logging">
<Version>1.7.1</Version>
</PackageReference>
<PackageReference Include="NLog.Schema">
<Version>4.7.7</Version>
<Version>4.7.8</Version>
</PackageReference>
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
Expand Down
48 changes: 27 additions & 21 deletions MidiPlayer.FluidSynth/Fluidsynth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,81 @@ namespace NativeFuncs {

internal static class Fluidsynth {

// must set to MidiPlayer.FluidSynth.csproj
#if RUNTIME_LINUX
const string LIBLARY = "libfluidsynth.so";
#elif RUNTIME_WINDOWS
const string LIBLARY = "libs/libfluidsynth-2.dll";
#endif
const UnmanagedType LP_Str = UnmanagedType.LPStr;

internal const int FLUID_OK = 0;

internal const int FLUID_FAILED = -1;

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern fluid_settings_t new_fluid_settings();

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern void delete_fluid_settings(fluid_settings_t settings);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern fluid_synth_t new_fluid_synth(fluid_settings_t settings);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern void delete_fluid_synth(fluid_synth_t synth);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern fluid_audio_driver_t new_fluid_audio_driver(fluid_settings_t settings, fluid_synth_t synth);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern void delete_fluid_audio_driver(fluid_audio_driver_t driver);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_synth_sfload(fluid_synth_t synth, [MarshalAs(LP_Str)] string filename, bool reset_presets);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_is_soundfont([MarshalAs(LP_Str)] string filename); // 1 or 0

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_synth_noteon(fluid_synth_t synth, int chan, int key, int vel);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_synth_noteoff(fluid_synth_t synth, int chan, int key);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern fluid_player_t new_fluid_player(fluid_synth_t synth);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int delete_fluid_player(fluid_player_t player);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_player_add(fluid_player_t player, [MarshalAs(LP_Str)] string midifile);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_is_midifile([MarshalAs(LP_Str)] string filename); // 1 or 0

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_player_play(fluid_player_t player);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_player_join(fluid_player_t player);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_player_stop(fluid_player_t player);

internal delegate int handle_midi_event_func_t(void_ptr data, fluid_midi_event_t evt);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_player_set_playback_callback(fluid_player_t player, handle_midi_event_func_t handler, void_ptr handler_data);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_synth_handle_midi_event(void_ptr data, fluid_midi_event_t evt);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_synth_program_change(fluid_synth_t synth, int chan, int program);

[DllImport("libfluidsynth.so")]
[DllImport(LIBLARY)]
internal static extern int fluid_synth_cc(fluid_synth_t synth, int chan, int ctrl, int val);
}
}
6 changes: 5 additions & 1 deletion MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>RUNTIME_LINUX</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog" Version="4.7.7" />
<PackageReference Include="NLog" Version="4.7.8" />
<PackageReference Include="NLog.Config" Version="4.7.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.1" />
<PackageReference Include="NLog.Schema" Version="4.7.8" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions MidiPlayer.FluidSynth/Synth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public static void Start() {
try {
if (!ready) {
Init();
if (!ready) {
Log.Error("failed to init.");
return;
}
}
adriver = Fluidsynth.new_fluid_audio_driver(setting, synth);
Fluidsynth.fluid_player_play(player);
Expand Down
107 changes: 107 additions & 0 deletions MidiPlayer.Win64/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7c8046

Please sign in to comment.