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 18, 2022
1 parent c2f9bfb commit 777fcac
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 132 deletions.
137 changes: 126 additions & 11 deletions MidiPlayer.Droid/MainActivity.Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Android.Support.V7.App;
using Android.Widget;

using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -44,27 +45,127 @@ public partial class MainActivity : AppCompatActivity {
/// initialize the component.
/// </summary>
void initializeComponent() {

/// <summary>
/// buttonLoadSoundFont
/// </summary>
_buttonloadSoundFont = FindViewById<Button>(Resource.Id.button_load_soundfont);
_buttonloadSoundFont.Click += buttonLoadSoundFont_Click;
_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
/// </summary>
_buttonloadMidiFile = FindViewById<Button>(Resource.Id.button_load_midifile);
_buttonloadMidiFile.Click += buttonLoadMidiFile_Click;
_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
/// </summary>
_buttonStart = FindViewById<Button>(Resource.Id.button_start);
_buttonStart.Click += buttonStart_Click;
_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
/// </summary>
_buttonStop = FindViewById<Button>(Resource.Id.button_stop);
_buttonStop.Click += buttonStop_Click;
_buttonStop.Click += (object sender, EventArgs e) => {
Log.Info("buttonStop clicked.");
try {
stopSong();
} catch (Exception ex) {
Log.Error(ex.Message);
}
};

/// <summary>
/// buttonAddPlaylist
/// </summary>
_buttonAddPlaylist = FindViewById<Button>(Resource.Id.button_add_playlist);
_buttonAddPlaylist.Click += buttonAddPlaylist_Click;
_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
/// </summary>
_buttonDeletePlaylist = FindViewById<Button>(Resource.Id.button_delete_playlist);
_buttonDeletePlaylist.Click += buttonDeletePlaylist_Click;
_buttonDeletePlaylist.Click += (object sender, EventArgs e) => {
Log.Info("buttonDeletePlaylist clicked.");
try {
_playList.Clear();
} catch (Exception ex) {
Log.Error(ex.Message);
}
};

// fader
/// <summary>
/// buttonSendSynth
/// </summary>
_buttonSendSynth = FindViewById<Button>(Resource.Id.button_send_synth);
_buttonSendSynth.Click += (object sender, EventArgs e) => {
Log.Info("buttonSendSynth clicked.");
try {
Mixer.Fader fader = Mixer.GetCurrent();
Log.Debug($"track index {fader.Index}: send a data to MIDI {fader.Channel} channel.");
Log.Debug($"prog: {fader.Program} pan: {fader.Pan} vol: {fader.Volume}.");
Data data = new() {
Channel = fader.Channel,
Program = fader.Program,
Pan = fader.Pan,
Volume = fader.Volume,
Mute = !fader.Sounds
};
EventQueue.Enqueue(fader.Index, data);
} catch (Exception ex) {
Log.Error(ex.Message);
}
};

/// <summary>
/// textViewNo, textViewChannel
/// </summary>
_textViewNo = FindViewById<TextView>(Resource.Id.text_view_no);
_textViewChannel = FindViewById<TextView>(Resource.Id.text_view_channel);

/// <summary>
/// numberPickerProg
/// </summary>
_numberPickerProg = FindViewById<NumberPicker>(Resource.Id.number_picker_prog);
_numberPickerProg.MinValue = 1;
_numberPickerProg.MaxValue = 128;
Expand All @@ -73,6 +174,10 @@ void initializeComponent() {
Log.Debug($"_numberPickerProg.Value: {_numberPickerProg.Value}");
fader.ProgramAsOneBased = _numberPickerProg.Value;
};

/// <summary>
/// numberPickerPan
/// </summary>
_numberPickerPan = FindViewById<NumberPicker>(Resource.Id.number_picker_pan);
_numberPickerPan.MinValue = 1;
_numberPickerPan.MaxValue = 128;
Expand All @@ -82,6 +187,10 @@ void initializeComponent() {
Log.Debug($"_numberPickerPan.Value: {_numberPickerPan.Value}");
fader.Pan = _numberPickerPan.Value;
};

/// <summary>
/// numberPickerVol
/// </summary>
_numberPickerVol = FindViewById<NumberPicker>(Resource.Id.number_picker_vol);
_numberPickerVol.MinValue = 1;
_numberPickerVol.MaxValue = 128;
Expand All @@ -91,21 +200,27 @@ void initializeComponent() {
Log.Debug($"_numberPickerVol.Value: {_numberPickerVol.Value}");
fader.Volume = _numberPickerVol.Value;
};

/// <summary>
/// checkBoxMute
/// </summary>
_checkBoxMute = FindViewById<CheckBox>(Resource.Id.check_box_mute);
_checkBoxMute.CheckedChange += (object sender, CheckBox.CheckedChangeEventArgs e) => {
var fader = Mixer.GetCurrent();
fader.Sounds = !_checkBoxMute.Checked;
};
_buttonSendSynth = FindViewById<Button>(Resource.Id.button_send_synth);
_buttonSendSynth.Click += buttonSendSynth_Click;

// list view title
/// <summary>
/// titleListView
/// </summary>
var titleList = new List<ListTitle>();
titleList.Add(new ListTitle() { Name = "Name", Instrument = "Voice", Channel = "Ch" });
_titleListView = FindViewById<ListView>(Resource.Id.list_view_title);
_titleListView.Adapter = new ListTitleAdapter(this, 0, titleList);

// list view item
/// <summary>
/// itemListView
/// </summary>
Enumerable.Range(MIDI_TRACK_BASE, MIDI_TRACK_COUNT).ToList().ForEach(x => {
_itemList.Add(new ListItem() { Name = "------", Instrument = "------", Channel = "---" });
});
Expand Down
120 changes: 0 additions & 120 deletions MidiPlayer.Droid/MainActivity.EventCallback.cs

This file was deleted.

1 change: 0 additions & 1 deletion MidiPlayer.Droid/MidiPlayer.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<ItemGroup>
<AndroidEnvironment Include="env.conf" />
<Compile Include="ListViewAdapter.cs" />
<Compile Include="MainActivity.EventCallback.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="MainActivity.Component.cs" />
<Compile Include="Resources\Resource.designer.cs" />
Expand Down

0 comments on commit 777fcac

Please sign in to comment.