Skip to content

Commit

Permalink
Merge pull request #52 from hiroxpepe/issue/13
Browse files Browse the repository at this point in the history
refactor: #13 keeping codes clean.
  • Loading branch information
hiroxpepe authored Mar 11, 2021
2 parents 73f3f55 + e55d715 commit 8d4a25a
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 85 deletions.
2 changes: 1 addition & 1 deletion MidiPlayer.Droid/MainActivity.Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace MidiPlayer.Droid {
public partial class MainActivity : AppCompatActivity {

///////////////////////////////////////////////////////////////////////////////////////////////
// private Methods [verb]
// private Methods [verb, verb phrases]

/// <summary>
/// initialize the component.
Expand Down
17 changes: 7 additions & 10 deletions MidiPlayer.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace MidiPlayer.Droid {
public partial class MainActivity : AppCompatActivity {

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

string soundFontPath = "undefined";

Expand Down Expand Up @@ -54,22 +54,19 @@ protected override void OnCreate(Bundle savedInstanceState) {
initializeComponent();
Conf.Load();

int _count = 0;
Synth.OnMessage += (IntPtr data, IntPtr evt) => {
//Log.Info($"OnMessage count: {_count}");
_count++;
Synth.Playbacking += (IntPtr data, IntPtr evt) => {
return Synth.HandleEvent(data, evt);
};

Synth.OnStart += () => {
Log.Info("OnStart called.");
Synth.Started += () => {
Log.Info("Started called.");
MainThread.BeginInvokeOnMainThread(() => {
Title = $"MidiPlayer: {Synth.MidiFilePath.ToFileName()} {Synth.SoundFontPath.ToFileName()}";
});
};

Synth.OnEnd += () => {
Log.Info("OnEnd called.");
Synth.Ended += () => {
Log.Info("Ended called.");
if (!playList.Ready) {
Synth.Stop();
Synth.Start();
Expand Down Expand Up @@ -436,7 +433,7 @@ void buttonSendSynth_16_Click(object sender, EventArgs e) {
}

///////////////////////////////////////////////////////////////////////////////////////////////
// private Methods [verb]
// private Methods [verb, verb phrases]

void requestPermissions() {
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != (int) Permission.Granted) {
Expand Down
70 changes: 35 additions & 35 deletions MidiPlayer.FluidSynth/Synth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace MidiPlayer {
public class Synth {

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

static fluid_settings_t setting = IntPtr.Zero;

Expand All @@ -32,13 +32,13 @@ public class Synth {

static handle_midi_event_func_t event_callback;

static Func<IntPtr, IntPtr, int> onMessage;
static Func<IntPtr, IntPtr, int> onPlaybacking;

static Action onStart;
static Action onStarted;

static Action onEnd;
static Action onEnded;

static Action<object, PropertyChangedEventArgs> onUpdate;
static Action<object, PropertyChangedEventArgs> onUpdated;

static string soundFontPath;

Expand All @@ -56,7 +56,7 @@ public class Synth {
// static Constructor

static Synth() {
onMessage += (void_ptr data, fluid_midi_event_t evt) => {
onPlaybacking += (void_ptr data, fluid_midi_event_t evt) => {
Enumerable.Range(0, 16).ToList().ForEach(x => {
var _data = EventQueue.Dequeue(x);
if (!(_data is null)) {
Expand Down Expand Up @@ -89,7 +89,7 @@ static Synth() {
}

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

public static string SoundFontPath {
get => soundFontPath;
Expand Down Expand Up @@ -120,33 +120,33 @@ public static bool Playing {
}

///////////////////////////////////////////////////////////////////////////////////////////////
// static Events [adjective]
// static Events [verb, verb phrase]

public static event Func<IntPtr, IntPtr, int> OnMessage {
public static event Func<IntPtr, IntPtr, int> Playbacking {
add {
onMessage += value;
event_callback = new handle_midi_event_func_t(onMessage);
onPlaybacking += value;
event_callback = new handle_midi_event_func_t(onPlaybacking);
}
remove => onMessage -= value;
remove => onPlaybacking -= value;
}

public static event Action OnStart {
add => onStart += value;
remove => onStart -= value;
public static event Action Started {
add => onStarted += value;
remove => onStarted -= value;
}

public static event Action OnEnd {
add => onEnd += value;
remove => onEnd -= value;
public static event Action Ended {
add => onEnded += value;
remove => onEnded -= value;
}

public static event Action<object, PropertyChangedEventArgs> OnUpdate {
add => onUpdate += value;
remove => onUpdate -= value;
public static event Action<object, PropertyChangedEventArgs> Updated {
add => onUpdated += value;
remove => onUpdated -= value;
}

///////////////////////////////////////////////////////////////////////////////////////////////
// public static Methods [verb]
// public static Methods [verb, verb phrases]

public static void Init() {
try {
Expand Down Expand Up @@ -177,7 +177,7 @@ public static void Init() {
}
Multi.StandardMidiFile = standardMidiFile;
Enumerable.Range(0, 16).ToList().ForEach(x => {
Multi.Get(x).PropertyChanged += onUpdateCallBack;
Multi.Get(x).PropertyChanged += onPropertyChanged;
});
int _result = fluid_player_add(player, MidiFilePath);
if (_result == FLUID_FAILED) {
Expand Down Expand Up @@ -205,11 +205,11 @@ public static void Start() {
adriver = new_fluid_audio_driver(setting, synth);
fluid_player_play(player);
Log.Info("start :)");
onStart();
onStarted();
fluid_player_join(player);
Log.Info("end :D");
if (stopping == false) {
onEnd();
onEnded();
}
} catch (Exception ex) {
Log.Error(ex.Message);
Expand Down Expand Up @@ -273,7 +273,7 @@ public static bool IsSounded(int channel) {
}

///////////////////////////////////////////////////////////////////////////////////////////////
// private static Methods [verb]
// private static Methods [verb, verb phrases]

static void final() {
try {
Expand All @@ -294,8 +294,8 @@ static void final() {
}
}

static void onUpdateCallBack(object sender, PropertyChangedEventArgs e) {
onUpdate(sender, e);
static void onPropertyChanged(object sender, PropertyChangedEventArgs e) {
onUpdated(sender, e);
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -304,7 +304,7 @@ static void onUpdateCallBack(object sender, PropertyChangedEventArgs e) {
static class Multi {

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

static Map<int, Track> trackMap;

Expand All @@ -318,7 +318,7 @@ static Multi() {
}

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

public static List<Track> List {
get => trackMap.Select(x => x.Value).ToList();
Expand All @@ -333,7 +333,7 @@ public static StandardMidiFile StandardMidiFile {
}

///////////////////////////////////////////////////////////////////////////////////////////
// public static Methods [verb]
// public static Methods [verb, verb phrases]

/// <summary>
/// NOTE_ON = 144
Expand Down Expand Up @@ -394,7 +394,7 @@ public static Track Get(int track) {
}

///////////////////////////////////////////////////////////////////////////////////////////
// private static Methods [verb]
// private static Methods [verb, verb phrases]

static void init() {
trackMap.Clear();
Expand All @@ -411,7 +411,7 @@ static void init() {
public class Track : INotifyPropertyChanged {

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

int index = -1;

Expand All @@ -433,15 +433,15 @@ public Track(int index) {
}

///////////////////////////////////////////////////////////////////////////////////////////
// Events [adjective]
// Events [verb, verb phrase]

/// <summary>
/// implementation for INotifyPropertyChanged
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;

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

public int Index {
get => index;
Expand Down
10 changes: 5 additions & 5 deletions MidiPlayer.Midi/StandardMidiFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MidiPlayer.Midi {
public class StandardMidiFile {

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

Sequence sequence;

Expand Down Expand Up @@ -39,7 +39,7 @@ public StandardMidiFile(string target) {
}

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

public int TrackCount {
get => sequence.Count - 1; // exclude conductor track;
Expand All @@ -50,21 +50,21 @@ public List<int> MidiChannelList {
}

///////////////////////////////////////////////////////////////////////////////////////////////
// public Methods [verb]
// public Methods [verb, verb phrases]

public string GetTrackName(int track) {
return nameAndMidiChannelMap[track].name;
}

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

int trackCountIncludeConductorTrack {
get => sequence.Count;
}

///////////////////////////////////////////////////////////////////////////////////////////////
// private Methods [verb]
// private Methods [verb, verb phrases]

string getTrackName(int track) {
var _trackName = "undefined";
Expand Down
6 changes: 3 additions & 3 deletions MidiPlayer.SoundFont/SoundFont .cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace MidiPlayer.SoundFont {
public class SoundFontInfo {

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

NAudio.SoundFont.SoundFont soundFont;

Expand Down Expand Up @@ -42,7 +42,7 @@ public SoundFontInfo(string target) {
}

///////////////////////////////////////////////////////////////////////////////////////////////
// public Methods [verb]
// public Methods [verb, verb phrases]

public string GetVoice(int bank, int prog) {
var _voice = map[bank];
Expand All @@ -60,7 +60,7 @@ public string GetVoice(int bank, int prog) {
class Voice {

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

public int Prog {
get; set;
Expand Down
2 changes: 1 addition & 1 deletion MidiPlayer.Win64/BufferedListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MidiPlayer.Win64 {
public class BufferedListView : ListView {

///////////////////////////////////////////////////////////////////////////////////////////////
// protected Methods [verb]
// protected Methods [verb, verb phrases]

protected override bool DoubleBuffered {
get {
Expand Down
16 changes: 8 additions & 8 deletions MidiPlayer.Win64/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace MidiPlayer.Win64 {
public partial class MainForm : Form {

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

string soundFontPath = "undefined";

Expand All @@ -37,12 +37,12 @@ void MainForm_Load(object sender, EventArgs e) {
Conf.Load();
initializeControl();

Synth.OnMessage += (IntPtr data, IntPtr evt) => {
Synth.Playbacking += (IntPtr data, IntPtr evt) => {
return Synth.HandleEvent(data, evt);
};

Synth.OnStart += () => {
Log.Info("OnStart called.");
Synth.Started += () => {
Log.Info("Started called.");
Invoke((MethodInvoker) (() => {
Text = $"MidiPlayer: {Synth.MidiFilePath.ToFileName()} {Synth.SoundFontPath.ToFileName()}";
listView.Items.Clear();
Expand All @@ -52,8 +52,8 @@ void MainForm_Load(object sender, EventArgs e) {
}));
};

Synth.OnEnd += () => {
Log.Info("OnEnd called.");
Synth.Ended += () => {
Log.Info("Ended called.");
if (!playList.Ready) {
Synth.Stop();
Synth.Start();
Expand All @@ -64,7 +64,7 @@ void MainForm_Load(object sender, EventArgs e) {
}
};

Synth.OnUpdate += (object sender, PropertyChangedEventArgs e) => {
Synth.Updated += (object sender, PropertyChangedEventArgs e) => {
var _track = (Synth.Track) sender;
Invoke(updateList(_track));
};
Expand Down Expand Up @@ -124,7 +124,7 @@ void buttonStop_Click(object sender, EventArgs e) {
}

///////////////////////////////////////////////////////////////////////////////////////////////
// private Methods [verb]
// private Methods [verb, verb phrases]

async void playSong() {
try {
Expand Down
Loading

0 comments on commit 8d4a25a

Please sign in to comment.