Skip to content

Commit

Permalink
feat: #67 held the sound font file and midi file paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroxpepe committed Mar 4, 2022
1 parent de745d5 commit f79dfd9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 68 deletions.
10 changes: 9 additions & 1 deletion MidiPlayer.Droid/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.studio.meowtoon.midiplayer" android:installLocation="auto">
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Base.Theme.MaterialComponents.Light.DarkActionBar.Bridge"></application>
<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Base.Theme.MaterialComponents.Light.DarkActionBar.Bridge"
android:requestLegacyExternalStorage="true"
>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.software.midi" android:required="true" />
Expand Down
2 changes: 1 addition & 1 deletion MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<DefineConstants>RUNTIME_WINDOWS</DefineConstants>
<DefineConstants>RUNTIME_LINUX</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
35 changes: 20 additions & 15 deletions MidiPlayer.Midi/StandardMidiFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -22,21 +23,25 @@ public class StandardMidiFile {
// Constructor

public StandardMidiFile(string target) {
_sequence = new Sequence();
_sequence.Format = 1;
_sequence.Load(target);
Map<int, (string name, int channel)> nameAndMidiChannelMap;
nameAndMidiChannelMap = new Map<int, (string name, int channel)>();
Enumerable.Range(0, _sequence.Count).ToList().ForEach(x => {
nameAndMidiChannelMap.Add(x, getTrackNameAndMidiChannel(x));
});
this._nameAndMidiChannelMap = new Map<int, (string name, int channel)>();
var idx = 0;
nameAndMidiChannelMap.ToList().ForEach(x => {
if (!x.Value.name.Equals("System Setup") && !(x.Value.name.Equals("") && x.Value.channel == -1)) { // no need track
this._nameAndMidiChannelMap.Add(idx++, x.Value);
}
});
try {
_sequence = new Sequence();
_sequence.Format = 1;
_sequence.Load(target);
Map<int, (string name, int channel)> nameAndMidiChannelMap;
nameAndMidiChannelMap = new Map<int, (string name, int channel)>();
Enumerable.Range(0, _sequence.Count).ToList().ForEach(x => {
nameAndMidiChannelMap.Add(x, getTrackNameAndMidiChannel(x));
});
this._nameAndMidiChannelMap = new Map<int, (string name, int channel)>();
var idx = 0;
nameAndMidiChannelMap.ToList().ForEach(x => {
if (!x.Value.name.Equals("System Setup") && !(x.Value.name.Equals("") && x.Value.channel == -1)) { // no need track
this._nameAndMidiChannelMap.Add(idx++, x.Value);
}
});
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
71 changes: 20 additions & 51 deletions MidiPlayer/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,100 +8,69 @@ namespace MidiPlayer {
public class Env {
#nullable enable

///////////////////////////////////////////////////////////////////////////////////////////////
// static Fields [nouns, noun phrases]

static string _soundFontDir = "Music";

static string _midiFileDir = "Music";

///////////////////////////////////////////////////////////////////////////////////////////////
// static Properties [noun, noun phrase, adjective]

public static string SoundFontDir {
get {
if (!Conf.Value.Synth.SoundFontDir.Equals("undefined")) {
_soundFontDir = Conf.Value.Synth.SoundFontDir;
}
return _soundFontDir;
}
set {
Conf.Value.Synth.SoundFontDir = value;
}
get => Conf.Value.Synth.SoundFontDir;
set => Conf.Value.Synth.SoundFontDir = value;
}

public static string MidiFileDir {
get {
if (!Conf.Value.Synth.MidiFileDir.Equals("undefined")) {
_midiFileDir = Conf.Value.Synth.MidiFileDir;
}
return _midiFileDir;
}
set {
Conf.Value.Synth.MidiFileDir = value;
}
get => Conf.Value.Synth.MidiFileDir;
set => Conf.Value.Synth.MidiFileDir = value;
}

public static string SoundFontDirForIntent {
get {
return _soundFontDir.Replace("/storage/emulated/0/", "").Replace("/", "%2F");
if (!ExistsSoundFont) {
return "Music";
}
return SoundFontDir.Replace("/storage/emulated/0/", "").Replace("/", "%2F");
}
}

public static string MidiFileDirForIntent {
get {
return _midiFileDir.Replace("/storage/emulated/0/", "").Replace("/", "%2F");
if (!ExistsMidiFile) {
return "Music";
}
return MidiFileDir.Replace("/storage/emulated/0/", "").Replace("/", "%2F");
}
}

public static string SoundFontName {
get {
return Conf.Value.Synth.SoundFontName;
}
set {
Conf.Value.Synth.SoundFontName = value;
}
get => Conf.Value.Synth.SoundFontName;
set => Conf.Value.Synth.SoundFontName = value;
}

public static string MidiFileName {
get {
return Conf.Value.Synth.MidiFileName;
}
set {
Conf.Value.Synth.MidiFileName = value;
}
get => Conf.Value.Synth.MidiFileName;
set => Conf.Value.Synth.MidiFileName = value;
}

public static string SoundFontPath {
get {
return $"{SoundFontDir}/{SoundFontName}";
}
get => $"{SoundFontDir}/{SoundFontName}";
set {
SoundFontDir = value.ToDirectoryName();
SoundFontName = value.ToFileName();
}
}

public static string MidiFilePath {
get {
return $"{MidiFileDir}/{MidiFileName}";
}
get => $"{MidiFileDir}/{MidiFileName}";
set {
MidiFileDir = value.ToDirectoryName();
MidiFileName = value.ToFileName();
}
}

public static bool ExistsSoundFont {
get {
return File.Exists(SoundFontPath);
}
get => File.Exists(SoundFontPath);
}

public static bool ExistsMidiFile {
get {
return File.Exists(MidiFilePath);
}
get => File.Exists(MidiFilePath);
}
}
}

0 comments on commit f79dfd9

Please sign in to comment.