Skip to content

Commit

Permalink
Merge pull request #105 from hiroxpepe/develop
Browse files Browse the repository at this point in the history
refactor: #13 keeping codes clean.
  • Loading branch information
hiroxpepe authored Mar 18, 2022
2 parents 66e705f + 777fcac commit fa8114d
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 137 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.

6 changes: 6 additions & 0 deletions MidiPlayer.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ void requestPermissions() {
}
}

/// <summary>
/// call Intent.
/// </summary>
void callIntent(string targetDir, int requestCode) {
var intent = new Intent(Intent.ActionOpenDocument);
var uri = Android.Net.Uri.Parse($"content://com.android.externalstorage.documents/document/primary%3A{targetDir}");
Expand All @@ -306,6 +309,9 @@ void callIntent(string targetDir, int requestCode) {
StartActivityForResult(intent, requestCode);
}

/// <summary>
/// get an actual path.
/// </summary>
static string getActualPathBy(Intent data) {
var uri = data.Data;
string docId = DocumentsContract.GetDocumentId(uri);
Expand Down
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
10 changes: 5 additions & 5 deletions MidiPlayer.FluidSynth/Synth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ static Synth() {
Enumerable.Range(MIDI_TRACK_BASE, MIDI_TRACK_COUNT).ToList().ForEach(trackIdx => {
var eventData = EventQueue.Dequeue(trackIdx);
if (eventData is not null) {
fluid_synth_program_change(_synth, trackIdx, eventData.Program);
fluid_synth_cc(_synth, trackIdx, (int) ControlChange.Pan, eventData.Pan);
fluid_synth_program_change(_synth, eventData.Channel, eventData.Program);
fluid_synth_cc(_synth, eventData.Channel, (int) ControlChange.Pan, eventData.Pan);
if (eventData.Mute) {
fluid_synth_cc(_synth, trackIdx, (int) ControlChange.Volume, MUTE_VOLUME);
fluid_synth_cc(_synth, eventData.Channel, (int) ControlChange.Volume, MUTE_VOLUME);
} else {
fluid_synth_cc(_synth, trackIdx, (int) ControlChange.Volume, eventData.Volume);
fluid_synth_cc(_synth, eventData.Channel, (int) ControlChange.Volume, eventData.Volume);
}
Task.Run(() => {
Multi.ApplyProgramChange(trackIdx, eventData.Program);
Multi.ApplyProgramChange(eventData.Channel, eventData.Program);
});
}
});
Expand Down

0 comments on commit fa8114d

Please sign in to comment.