diff --git a/MidiPlayer.Droid/Properties/AndroidManifest.xml b/MidiPlayer.Droid/Properties/AndroidManifest.xml index f33a178..9911f6d 100644 --- a/MidiPlayer.Droid/Properties/AndroidManifest.xml +++ b/MidiPlayer.Droid/Properties/AndroidManifest.xml @@ -1,7 +1,15 @@  - + + diff --git a/MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj b/MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj index 7b76755..4eaac08 100644 --- a/MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj +++ b/MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj @@ -2,7 +2,7 @@ netstandard2.1 - RUNTIME_WINDOWS + RUNTIME_LINUX diff --git a/MidiPlayer.Midi/StandardMidiFile.cs b/MidiPlayer.Midi/StandardMidiFile.cs index 627b4c4..ed25715 100644 --- a/MidiPlayer.Midi/StandardMidiFile.cs +++ b/MidiPlayer.Midi/StandardMidiFile.cs @@ -1,4 +1,5 @@  +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -22,21 +23,25 @@ public class StandardMidiFile { // Constructor public StandardMidiFile(string target) { - _sequence = new Sequence(); - _sequence.Format = 1; - _sequence.Load(target); - Map nameAndMidiChannelMap; - nameAndMidiChannelMap = new Map(); - Enumerable.Range(0, _sequence.Count).ToList().ForEach(x => { - nameAndMidiChannelMap.Add(x, getTrackNameAndMidiChannel(x)); - }); - this._nameAndMidiChannelMap = new Map(); - 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 nameAndMidiChannelMap; + nameAndMidiChannelMap = new Map(); + Enumerable.Range(0, _sequence.Count).ToList().ForEach(x => { + nameAndMidiChannelMap.Add(x, getTrackNameAndMidiChannel(x)); + }); + this._nameAndMidiChannelMap = new Map(); + 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); + } } /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/MidiPlayer/Env.cs b/MidiPlayer/Env.cs index 7c432fb..98f3e96 100644 --- a/MidiPlayer/Env.cs +++ b/MidiPlayer/Env.cs @@ -8,74 +8,49 @@ 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(); @@ -83,9 +58,7 @@ public static string SoundFontPath { } public static string MidiFilePath { - get { - return $"{MidiFileDir}/{MidiFileName}"; - } + get => $"{MidiFileDir}/{MidiFileName}"; set { MidiFileDir = value.ToDirectoryName(); MidiFileName = value.ToFileName(); @@ -93,15 +66,11 @@ public static string MidiFilePath { } 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); } } }