Skip to content

Commit

Permalink
Merge pull request #103 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 17, 2022
2 parents 2cdaa88 + f6053d8 commit 8d398ad
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 42 deletions.
4 changes: 2 additions & 2 deletions MidiPlayer.Droid/MainActivity.EventCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ void buttonSendSynth_Click(object sender, EventArgs e) {
Log.Info($"send a data to MIDI {midiChannel} channel.");
Log.Info($"prog: {_numberPickerProg.Value} pan: {_numberPickerPan.Value} vol: {_numberPickerVol.Value}.");
Data data = new() {
Prog = _numberPickerProg.Value,
Program = _numberPickerProg.Value,
Pan = _numberPickerPan.Value,
Vol = _numberPickerVol.Value,
Volume = _numberPickerVol.Value,
Mute = _checkBoxMute.Checked
};
EventQueue.Enqueue(midiChannel, data);
Expand Down
32 changes: 16 additions & 16 deletions MidiPlayer.FluidSynth/Synth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ static Synth() {
Multi.ApplyControlChange(channel, control, value);
}
});
Enumerable.Range(MIDI_TRACK_BASE, MIDI_TRACK_COUNT).ToList().ForEach(x => {
var eventData = EventQueue.Dequeue(x);
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, x, eventData.Prog);
fluid_synth_cc(_synth, x, (int) ControlChange.Pan, eventData.Pan);
fluid_synth_program_change(_synth, trackIdx, eventData.Program);
fluid_synth_cc(_synth, trackIdx, (int) ControlChange.Pan, eventData.Pan);
if (eventData.Mute) {
fluid_synth_cc(_synth, x, (int) ControlChange.Volume, MUTE_VOLUME);
fluid_synth_cc(_synth, trackIdx, (int) ControlChange.Volume, MUTE_VOLUME);
} else {
fluid_synth_cc(_synth, x, (int) ControlChange.Volume, eventData.Vol);
fluid_synth_cc(_synth, trackIdx, (int) ControlChange.Volume, eventData.Volume);
}
Task.Run(() => {
Multi.ApplyProgramChange(x, eventData.Prog);
Multi.ApplyProgramChange(trackIdx, eventData.Program);
});
}
});
Expand Down Expand Up @@ -353,13 +353,13 @@ static Multi() {
}

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

public static List<Track> List {
internal static List<Track> List {
get => _trackMap.Select(x => x.Value).ToList();
}

public static StandardMidiFile StandardMidiFile {
internal static StandardMidiFile StandardMidiFile {
get => _standardMidiFile;
set {
_standardMidiFile = value;
Expand All @@ -368,33 +368,33 @@ public static StandardMidiFile StandardMidiFile {
}

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

/// <summary>
/// NOTE_ON = 144
/// </summary>
public static void ApplyNoteOn(int channel) {
internal static void ApplyNoteOn(int channel) {
_trackMap.Where(x => x.Value.Channel == channel).ToList().ForEach(x => x.Value.Sounds = true);
}

/// <summary>
/// NOTE_OFF = 128
/// </summary>
public static void ApplyNoteOff(int channel) {
internal static void ApplyNoteOff(int channel) {
_trackMap.Where(x => x.Value.Channel == channel).ToList().ForEach(x => x.Value.Sounds = false);
}

/// <summary>
/// PROGRAM_CHANGE = 192
/// </summary>
public static void ApplyProgramChange(int channel, int program) {
internal static void ApplyProgramChange(int channel, int program) {
_trackMap.Where(x => x.Value.Channel == channel).ToList().ForEach(x => x.Value.Program = program);
}

/// <summary>
/// CONTROL_CHANGE = 176
/// </summary>
public static void ApplyControlChange(int channel, int control, int value) {
internal static void ApplyControlChange(int channel, int control, int value) {
// BANK_SELECT_MSB = 0 [-- drums: 127 --]
// _type: 176, _control: 0, _value: 127
// BANK_SELECT_LSB = 32
Expand Down Expand Up @@ -428,7 +428,7 @@ public static void ApplyControlChange(int channel, int control, int value) {
/// <summary>
/// get a trak by index.
/// </summary>
public static Track GetBy(int index) {
internal static Track GetBy(int index) {
var track = _trackMap[index];
return track;
}
Expand Down
6 changes: 3 additions & 3 deletions MidiPlayer.SoundFont/SoundFont .cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public string GetVoice(int bank, int prog) {
class Voice {

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

public int Prog {
internal int Prog {
get; set;
}

public string Name {
internal string Name {
get; set;
}
}
Expand Down
7 changes: 5 additions & 2 deletions MidiPlayer/Conf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ public class Conf {
static Json _json = null;

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

public static bool Ready {
internal static bool Ready {
get => !(_json is null);
}

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

public static App Value {
get {
if (_json is null) {
Expand Down
41 changes: 28 additions & 13 deletions MidiPlayer/EventQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class Map<K, V> : Dictionary<K, V> {
public class EventQueue {
#nullable enable

///////////////////////////////////////////////////////////////////////////////////////////////
// Const [nouns]

const int MIDI_TRACK_BASE = 0;
const int MIDI_TRACK_COUNT = 16;

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

Expand All @@ -25,18 +31,20 @@ public class EventQueue {

static EventQueue() {
_queueMap = new();
Enumerable.Range(0, 16).ToList().ForEach(x => _queueMap.Add(x, new()));
Enumerable.Range(MIDI_TRACK_BASE, MIDI_TRACK_COUNT).ToList().ForEach(
trackIdx => _queueMap.Add(trackIdx, new())
);
}

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

public static void Enqueue(int idx, Data value) {
_queueMap[idx].Enqueue(value);
public static void Enqueue(int trackIdx, Data value) {
_queueMap[trackIdx].Enqueue(value);
}

public static Data Dequeue(int idx) {
return _queueMap[idx].Count == 0 ? null : _queueMap[idx].Dequeue();
public static Data Dequeue(int trackIdx) {
return _queueMap[trackIdx].Count == 0 ? null : _queueMap[trackIdx].Dequeue();
}
}

Expand All @@ -48,30 +56,37 @@ public class Data {
///////////////////////////////////////////////////////////////////////////////////////////////
// Properties [noun, noun phrase, adjective]

int _prog;
int _channel;

int _program;

int _pan;

int _vol;
int _volume;

bool _mute;

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

public int Prog {
get => _prog - 1;
set => _prog = value;
public int Channel {
get => _channel - 1;
set => _channel = value;
}

public int Program {
get => _program - 1;
set => _program = value;
}

public int Pan {
get => _pan - 1;
set => _pan = value;
}

public int Vol {
get => _vol - 1;
set => _vol = value;
public int Volume {
get => _volume - 1;
set => _volume = value;
}

public bool Mute {
Expand Down
Loading

0 comments on commit 8d398ad

Please sign in to comment.