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 17, 2022
1 parent ef2242b commit 2cdaa88
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 39 deletions.
16 changes: 16 additions & 0 deletions MidiPlayer.Droid/MainActivity.Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,31 @@ void initializeComponent() {
_numberPickerProg = FindViewById<NumberPicker>(Resource.Id.number_picker_prog);
_numberPickerProg.MinValue = 1;
_numberPickerProg.MaxValue = 128;
_numberPickerProg.ValueChanged += (object sender, NumberPicker.ValueChangeEventArgs e) => {
var fader = Mixer.GetCurrent();
fader.Program = _numberPickerProg.Value;
};
_numberPickerPan = FindViewById<NumberPicker>(Resource.Id.number_picker_pan);
_numberPickerPan.MinValue = 1;
_numberPickerPan.MaxValue = 128;
_numberPickerPan.Value = 65;
_numberPickerPan.ValueChanged += (object sender, NumberPicker.ValueChangeEventArgs e) => {
var fader = Mixer.GetCurrent();
fader.Pan = _numberPickerPan.Value;
};
_numberPickerVol = FindViewById<NumberPicker>(Resource.Id.number_picker_vol);
_numberPickerVol.MinValue = 1;
_numberPickerVol.MaxValue = 128;
_numberPickerVol.Value = 104;
_numberPickerVol.ValueChanged += (object sender, NumberPicker.ValueChangeEventArgs e) => {
var fader = Mixer.GetCurrent();
fader.Volume = _numberPickerVol.Value;
};
_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;

Expand Down
14 changes: 6 additions & 8 deletions MidiPlayer.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,21 @@ protected override void OnCreate(Bundle? savedInstanceState) {
/// add a callback function to be called when the mixer updated.
/// </summary>
Mixer.Updated += (object sender, PropertyChangedEventArgs e) => {
return;
// FIXME:
if ((((Mixer.Fader) sender).Index == Mixer.Current)) {
if (e.PropertyName is nameof(Mixer.Fader.Name)) {
Log.Debug($"fadar {Mixer.Current}'s Name is updated.");
Log.Debug($"fadar {Mixer.Current} Name is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Bank)) {
Log.Debug($"fadar {Mixer.Current}'s Bank is updated.");
Log.Debug($"fadar {Mixer.Current} Bank is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Program)) {
Log.Debug($"fadar {Mixer.Current}'s Program is updated.");
Log.Debug($"fadar {Mixer.Current} Program is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Volume)) {
Log.Debug($"fadar {Mixer.Current}'s Volume is updated.");
Log.Debug($"fadar {Mixer.Current} Volume is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Pan)) {
Log.Debug($"fadar {Mixer.Current}'s Pan is updated.");
Log.Debug($"fadar {Mixer.Current} Pan is updated.");
}
}
};
Expand Down Expand Up @@ -391,7 +389,7 @@ void loadFader() {
void saveFader() {
var fader = Mixer.GetPrevious();
if (int.TryParse(_textViewChannel.Text, out int channel)) {
fader.Channel = channel;
fader.Channel = channel; // MEMO:
fader.Program = _numberPickerProg.Value;
fader.Pan = _numberPickerPan.Value;
fader.Volume = _numberPickerVol.Value;
Expand Down
19 changes: 11 additions & 8 deletions MidiPlayer.FluidSynth/Synth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static void Init() {
}
Multi.StandardMidiFile = _standardMidiFile;
Enumerable.Range(MIDI_TRACK_BASE, MIDI_TRACK_COUNT).ToList().ForEach(x => {
Multi.Get(x).PropertyChanged += onPropertyChanged;
Multi.GetBy(x).PropertyChanged += onPropertyChanged;
});
int result = fluid_player_add(_player, MidiFilePath);
if (result == FLUID_FAILED) {
Expand Down Expand Up @@ -273,20 +273,20 @@ public static int GetChannel(IntPtr evt) {
}

public static int GetChannel(int track) {
var channel = Multi.Get(track).Channel;
var channel = Multi.GetBy(track).Channel;
return channel;
}

public static int GetBank(int track) {
var bank = Multi.Get(track).Bank;
var bank = Multi.GetBy(track).Bank;
if (bank == -1) { // unset BANK_SELECT_LSB = 32
bank = 0;
}
return bank;
}

public static int GetProgram(int track) {
var program = Multi.Get(track).Program;
var program = Multi.GetBy(track).Program;
return program;
}

Expand All @@ -298,12 +298,12 @@ public static string GetVoice(int track) {
}

public static string GetTrackName(int track) {
var name = Multi.Get(track).Name;
var name = Multi.GetBy(track).Name;
return name;
}

public static bool IsSounded(int channel) {
return Multi.Get(channel).Sounds;
return Multi.GetBy(channel).Sounds;
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -425,7 +425,10 @@ public static void ApplyControlChange(int channel, int control, int value) {
}
}

public static Track Get(int index) {
/// <summary>
/// get a trak by index.
/// </summary>
public static Track GetBy(int index) {
var track = _trackMap[index];
return track;
}
Expand Down Expand Up @@ -470,7 +473,7 @@ public class Track : INotifyPropertyChanged {
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor

public Track(int index) {
internal Track(int index) {
_index = index;
}

Expand Down
Loading

0 comments on commit 2cdaa88

Please sign in to comment.