Skip to content

Commit

Permalink
refactor: #13 keeping codes clean.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroxpepe committed Mar 8, 2022
1 parent dae2f31 commit 6eeb140
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 80 deletions.
116 changes: 116 additions & 0 deletions MidiPlayer.Droid/MainActivity.EventCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

using Android.Support.V7.App;
using Android.Widget;

using System;

namespace MidiPlayer.Droid {
/// <summary>
/// partial class for event callback functions.
/// </summary>
public partial class MainActivity : AppCompatActivity {
#nullable enable

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

/// <summary>
/// buttonLoadSoundFont Click.
/// </summary>
void buttonLoadSoundFont_Click(object sender, EventArgs e) {
Log.Info("buttonLoadSoundFont clicked.");
try {
if (Synth.Playing) {
stopSong();
}
callIntent(Env.SoundFontDirForIntent, (int) Request.SoundFont);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

/// <summary>
/// buttonLoadMidiFile Click.
/// </summary>
void buttonLoadMidiFile_Click(object sender, EventArgs e) {
Log.Info("buttonLoadMidiFile clicked.");
try {
if (Synth.Playing) {
stopSong();
}
callIntent(Env.MidiFileDirForIntent, (int) Request.MidiFile);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

/// <summary>
/// buttonStart Click.
/// </summary>
void buttonStart_Click(object sender, EventArgs e) {
Log.Info("buttonStart clicked.");
try {
if (!_midiFilePath.HasValue()) { // FIXME: case sounFdont
Log.Warn("midiFilePath has no value.");
return;
}
playSong();
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

/// <summary>
/// buttonStop Click.
/// </summary>
void buttonStop_Click(object sender, EventArgs e) {
Log.Info("buttonStop clicked.");
try {
stopSong();
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

/// <summary>
/// buttonAddPlaylist Click.
/// </summary>
void buttonAddPlaylist_Click(object sender, EventArgs e) {
Log.Info("buttonAddPlaylist clicked.");
try {
callIntent(Env.MidiFileDir, (int) Request.AddPlayList);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

/// <summary>
/// buttonDeletePlaylist Click.
/// </summary>
void buttonDeletePlaylist_Click(object sender, EventArgs e) {
Log.Info("buttonDeletePlaylist clicked.");
try {
_playList.Clear();
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

/// <summary>
/// buttonSendSynth_1 Click.
/// </summary>
void buttonSendSynth_1_Click(object sender, EventArgs e) {
Log.Info("buttonSendSynth_1 clicked.");
try {
Data data = new() {
Prog = FindViewById<NumberPicker>(Resource.Id.number_picker_prog_1).Value,
Pan = FindViewById<NumberPicker>(Resource.Id.number_picker_pan_1).Value,
Vol = FindViewById<NumberPicker>(Resource.Id.number_picker_vol_1).Value,
};
EventQueue.Enqueue((int) MidiChannel.ch1, data);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}
}
}
82 changes: 3 additions & 79 deletions MidiPlayer.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Android.Support.V4.App;
using Android.Support.V4.Content;
using Android.Support.V7.App;
using Android.Widget;

using System;
using System.Threading.Tasks;
Expand Down Expand Up @@ -186,87 +185,12 @@ protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result
}
}

void buttonLoadSoundFont_Click(object sender, EventArgs e) {
Log.Info("buttonLoadSoundFont clicked.");
try {
if (Synth.Playing) {
stopSong();
}
callIntent(Env.SoundFontDirForIntent, (int) Request.SoundFont);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

void buttonLoadMidiFile_Click(object sender, EventArgs e) {
Log.Info("buttonLoadMidiFile clicked.");
try {
if (Synth.Playing) {
stopSong();
}
callIntent(Env.MidiFileDirForIntent, (int) Request.MidiFile);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

void buttonStart_Click(object sender, EventArgs e) {
Log.Info("buttonStart clicked.");
try {
if (!_midiFilePath.HasValue()) { // FIXME: case sounFdont
Log.Warn("midiFilePath has no value.");
return;
}
playSong();
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

void buttonStop_Click(object sender, EventArgs e) {
Log.Info("buttonStop clicked.");
try {
stopSong();
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

void buttonAddPlaylist_Click(object sender, EventArgs e) {
Log.Info("buttonAddPlaylist clicked.");
try {
callIntent(Env.MidiFileDir, (int) Request.AddPlayList);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

void buttonDeletePlaylist_Click(object sender, EventArgs e) {
Log.Info("buttonDeletePlaylist clicked.");
try {
_playList.Clear();
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

void buttonSendSynth_1_Click(object sender, EventArgs e) {
Log.Info("buttonSendSynth_1 clicked.");
try {
Data data = new() {
Prog = FindViewById<NumberPicker>(Resource.Id.number_picker_prog_1).Value,
Pan = FindViewById<NumberPicker>(Resource.Id.number_picker_pan_1).Value,
Vol = FindViewById<NumberPicker>(Resource.Id.number_picker_vol_1).Value,
};
EventQueue.Enqueue((int) MidiChannel.ch1, data);
} catch (Exception ex) {
Log.Error(ex.Message);
}
}

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

/// <summary>
/// request permissions.
/// </summary>
void requestPermissions() {
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != (int) Permission.Granted) {
ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage }, 0);
Expand Down
1 change: 1 addition & 0 deletions MidiPlayer.Droid/MidiPlayer.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.EventCallback.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="MainActivity.Component.cs" />
<Compile Include="Resources\Resource.designer.cs" />
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 @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>9</LangVersion>
<DefineConstants>RUNTIME_WINDOWS</DefineConstants>
<DefineConstants>RUNTIME_LINUX</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 6eeb140

Please sign in to comment.