Skip to content

Commit

Permalink
Merge pull request #101 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 16, 2022
2 parents b11a85d + 390311c commit ef2242b
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 86 deletions.
29 changes: 27 additions & 2 deletions MidiPlayer.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,38 @@ protected override void OnCreate(Bundle? savedInstanceState) {
};

/// <summary>
/// add a callback function to be called when the mixer updated.
/// add a callback function to be called when the mixer selected.
/// </summary>
Mixer.Selected += (object sender, PropertyChangedEventArgs e) => {
if (e.PropertyName is nameof(Mixer.Current)) {
loadFader();
}
};

/// <summary>
/// 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.");
}
if (e.PropertyName is nameof(Mixer.Fader.Bank)) {
Log.Debug($"fadar {Mixer.Current}'s Bank is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Program)) {
Log.Debug($"fadar {Mixer.Current}'s Program is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Volume)) {
Log.Debug($"fadar {Mixer.Current}'s Volume is updated.");
}
if (e.PropertyName is nameof(Mixer.Fader.Pan)) {
Log.Debug($"fadar {Mixer.Current}'s Pan is updated.");
}
}
};
}

/// <summary>
Expand Down Expand Up @@ -314,7 +339,7 @@ void updateList(Synth.Track track) {
listItem.Channel = track.Channel.ToString();

// update a fader.
Fader fader = Mixer.GetBy(trackIdx);
var fader = Mixer.GetBy(trackIdx);
fader.Program = track.Program + 1; // zero base to one base;
fader.Pan = track.Pan + 1; // zero base to one base;
fader.Volume = track.Volume + 1; // zero base to one base;
Expand Down
181 changes: 97 additions & 84 deletions MidiPlayer/Mixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,32 @@ static Mixer() {
_mixer = new();
_current = 0;
Enumerable.Range(MIDI_TRACK_BASE, MIDI_TRACK_COUNT).ToList().ForEach(x => {
_mixer.Add(x, new Fader(x));
Fader fader = new(x);
fader.Updated += Updated;
_mixer.Add(x, fader);
});
}

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

/// <summary>
/// static selected event handler.
/// selected event handler.
/// </summary>
/// <remarks>
/// called when Mixer's channel is clicked.<br/>
/// </remarks>
public static event PropertyChangedEventHandler? Selected;

///////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// updated event handler.
/// </summary>
/// <remarks>
/// called when Fader's properties change.<br/>
/// </remarks>
public static event PropertyChangedEventHandler? Updated;

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

/// <summary>
Expand All @@ -63,7 +76,7 @@ public static int Current {
}
}

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

/// <summary>
Expand All @@ -86,117 +99,117 @@ public static Fader GetPrevious() {
public static Fader GetBy(int index) {
return _mixer[index];
}
}

/// <summary>
/// Fader class.
/// </summary>
public class Fader {
/// <summary>
/// Fader class.
/// </summary>
public class Fader {
#nullable enable

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

int _index = -1;
int _index = -1;

bool _sounds = true; // mute param.
bool _sounds = true; // mute param.

string _name = "undefined";
string _name = "undefined";

int _channel = -1;
int _channel = -1;

int _bank = 0;
int _bank = 0;

int _program = 0;
int _program = 0;

int _volume = 104;
int _volume = 104;

int _pan = 64; // center
int _pan = 64; // center

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor

public Fader(int index) {
_index = index;
}
public Fader(int index) {
_index = index;
}

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

/// <summary>
/// updated event handler.
/// </summary>
public event PropertyChangedEventHandler? Updated;
/// <summary>
/// updated event handler.
/// </summary>
public event PropertyChangedEventHandler? Updated;

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

public int Index {
get => _index;
set {
_index = value;
Updated?.Invoke(this, new(nameof(Index)));
public int Index {
get => _index;
set {
_index = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Index))); // FIXME: not Invoke if two values are the same.
}
}
}

public bool Sounds {
get => _sounds;
set {
_sounds = value;
Updated?.Invoke(this, new(nameof(Sounds)));
public bool Sounds {
get => _sounds;
set {
_sounds = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Sounds))); // FIXME: not Invoke if two values are the same.
}
}
}

public string Name {
get => _name;
set {
_name = value;
Updated?.Invoke(this, new(nameof(Name)));
public string Name {
get => _name;
set {
_name = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Name))); // FIXME: not Invoke if two values are the same.
}
}
}

public int Channel {
get => _channel;
set {
_channel = value;
Updated?.Invoke(this, new(nameof(Channel)));
public int Channel {
get => _channel;
set {
_channel = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Channel))); // FIXME: not Invoke if two values are the same.
}
}
}

public int Bank {
get {
if (_channel == 9 && _bank != 128) {
return 128; // Drum
public int Bank {
get {
if (_channel == 9 && _bank != 128) {
return 128; // Drum
}
return _bank;
}
set {
_bank = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Bank))); // FIXME: not Invoke if two values are the same.
}
return _bank;
}
set {
_bank = value;
Updated?.Invoke(this, new(nameof(Bank)));
}
}

public int Program {
get => _program;
set {
_program = value;
Updated?.Invoke(this, new(nameof(Program)));
public int Program {
get => _program;
set {
_program = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Program))); // FIXME: not Invoke if two values are the same.
}
}
}

public int Volume {
get => _volume;
set {
_volume = value;
Updated?.Invoke(this, new(nameof(Volume)));
public int Volume {
get => _volume;
set {
_volume = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Volume))); // FIXME: not Invoke if two values are the same.
}
}
}

public int Pan {
get => _pan;
set {
_pan = value;
Updated?.Invoke(this, new(nameof(Pan)));
public int Pan {
get => _pan;
set {
_pan = value; // TODO: Compare if the value is the same value as the previous.
Updated?.Invoke(this, new(nameof(Pan))); // FIXME: not Invoke if two values are the same.
}
}
}
}
Expand Down

0 comments on commit ef2242b

Please sign in to comment.