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 5, 2022
1 parent a215f21 commit dae2f31
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions MidiPlayer.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public partial class MainActivity : AppCompatActivity {
// Constructor

public MainActivity() {
_playList = new PlayList();
_playList = new();
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -253,7 +253,7 @@ void buttonDeletePlaylist_Click(object sender, EventArgs e) {
void buttonSendSynth_1_Click(object sender, EventArgs e) {
Log.Info("buttonSendSynth_1 clicked.");
try {
var data = new Data() {
Data data = new() {
Prog = FindViewById<NumberPicker>(Resource.Id.number_picker_prog_1).Value,
Pan = FindViewById<NumberPicker>(Resource.Id.number_picker_pan_1).Value,
Vol = FindViewById<NumberPicker>(Resource.Id.number_picker_vol_1).Value,
Expand Down
2 changes: 1 addition & 1 deletion MidiPlayer.FluidSynth/MidiPlayer.FluidSynth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>9</LangVersion>
<DefineConstants>RUNTIME_LINUX</DefineConstants>
<DefineConstants>RUNTIME_WINDOWS</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MidiPlayer.FluidSynth/Synth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static class Multi {
// static Constructor

static Multi() {
_trackMap = new Map<int, Track>();
_trackMap = new();
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions MidiPlayer.Midi/StandardMidiFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public class StandardMidiFile {

public StandardMidiFile(string target) {
try {
_sequence = new Sequence();
_sequence = new();
_sequence.Format = 1;
_sequence.Load(target);
Map<int, (string name, int channel)> nameAndMidiChannelMap;
nameAndMidiChannelMap = new Map<int, (string name, int channel)>();
nameAndMidiChannelMap = new();
Enumerable.Range(0, _sequence.Count).ToList().ForEach(x => {
nameAndMidiChannelMap.Add(x, getTrackNameAndMidiChannel(x));
});
this._nameAndMidiChannelMap = new Map<int, (string name, int channel)>();
_nameAndMidiChannelMap = new();
var idx = 0;
nameAndMidiChannelMap.ToList().ForEach(x => {
if (!x.Value.name.Equals("System Setup") && !(x.Value.name.Equals("") && x.Value.channel == -1)) { // no need track
this._nameAndMidiChannelMap.Add(idx++, x.Value);
_nameAndMidiChannelMap.Add(idx++, x.Value);
}
});
} catch (Exception ex) {
Expand Down
8 changes: 4 additions & 4 deletions MidiPlayer.SoundFont/SoundFont .cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public class SoundFontInfo {
public SoundFontInfo(string target) {
try {
_soundFont = new NAudio.SoundFont.SoundFont(target);
var map = new Map<int, List<Voice>>();
Map<int, List<Voice>> map = new();
_soundFont.Presets.ToList().ForEach(x => {
if (!map.ContainsKey(x.Bank)) {
var newList = new List<Voice>();
List<Voice> newList = new();
newList.Add(new Voice() { Prog = x.PatchNumber, Name = x.Name });
map.Add(x.Bank, newList); // new bank and new voice
} else {
map[x.Bank].Add(new Voice() { Prog = x.PatchNumber, Name = x.Name }); // exists bank and new voice
}
});
this._map = new Map<int, List<Voice>>();
_map = new();
map.OrderBy(x => x.Key).ToList().ForEach(x => { // sort bank
this._map.Add(x.Key, x.Value.OrderBy(_x => _x.Prog).ToList()); // sort prog
_map.Add(x.Key, x.Value.OrderBy(_x => _x.Prog).ToList()); // sort prog
});
} catch (Exception ex) {
Log.Error(ex.Message);
Expand Down
14 changes: 7 additions & 7 deletions MidiPlayer.Win64/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class MainForm : Form {
public MainForm() {
InitializeComponent();
DoubleBuffered = true;
_playList = new PlayList();
_playList = new();
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -230,22 +230,22 @@ void initializeControl() {
_listView.GridLines = true;
_listView.Sorting = SortOrder.None; // do not sort automatically.
_listView.View = View.Details;
var column1 = new ColumnHeader();
ColumnHeader column1 = new();
column1.Text = "On";
column1.Width = 35;
var column2 = new ColumnHeader();
ColumnHeader column2 = new();
column2.Text = "Name";
column2.Width = 115;
var column3 = new ColumnHeader();
ColumnHeader column3 = new();
column3.Text = "Voice";
column3.Width = 115;
var column4 = new ColumnHeader();
ColumnHeader column4 = new();
column4.Text = "Chan";
column4.Width = 45;
var column5 = new ColumnHeader();
ColumnHeader column5 = new();
column5.Text = "Bank";
column5.Width = 45;
var column6 = new ColumnHeader();
ColumnHeader column6 = new();
column6.Text = "Prog";
column6.Width = 45;
ColumnHeader[] columnHeaderArray = { column1, column2, column3, column4, column5, column6 };
Expand Down
2 changes: 1 addition & 1 deletion MidiPlayer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MidiPlayer", "MidiPlayer\Mi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MidiPlayer.FluidSynth", "MidiPlayer.FluidSynth\MidiPlayer.FluidSynth.csproj", "{D63EE98D-8A01-440E-8E7A-B924B41FAFA6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MidiPlayerTests", "MidiPlayerTests\MidiPlayerTests.csproj", "{0C4ED722-5C23-4C5B-A478-A8D9279C413C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MidiPlayerTest", "MidiPlayerTest\MidiPlayerTest.csproj", "{0C4ED722-5C23-4C5B-A478-A8D9279C413C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MidiPlayer.Win64", "MidiPlayer.Win64\MidiPlayer.Win64.csproj", "{A99AAD96-61C9-481B-8156-DBCD279A742A}"
EndProject
Expand Down
6 changes: 3 additions & 3 deletions MidiPlayer/Conf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public static void Load() {
Log.Debug("Conf midiFileDir: " + _json.App.Synth.MidiFileDir);
Log.Debug("Conf midiFileName: " + _json.App.Synth.MidiFileName);
} else {
Synth synth = new Synth();
Synth synth = new();
synth.SoundFontDir = "undefined";
synth.MidiFileDir = "undefined";
App app = new App();
App app = new();
app.PlayList = null;
app.Synth = synth;
_json = new Json();
_json = new();
_json.App = app;
}
}
Expand Down
6 changes: 3 additions & 3 deletions MidiPlayer/EventQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class EventQueue {
///////////////////////////////////////////////////////////////////////////////////////////////
// static Fields [nouns, noun phrases]

static Map<int, Queue<Data>> _queueMap = new Map<int, Queue<Data>>();
static Map<int, Queue<Data>> _queueMap = new();

///////////////////////////////////////////////////////////////////////////////////////////////
// static Constructor

static EventQueue() {
_queueMap = new Map<int, Queue<Data>>();
Enumerable.Range(0, 16).ToList().ForEach(x => _queueMap.Add(x, new Queue<Data>()));
_queueMap = new();
Enumerable.Range(0, 16).ToList().ForEach(x => _queueMap.Add(x, new()));
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions MidiPlayer/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ public static class Log {
// public static Methods [verb, verb phrases]

public static void Fatal(string target) {
LogEventInfo eventInfo = new LogEventInfo(LogLevel.Fatal, _logger.Name, target);
var eventInfo = new LogEventInfo(LogLevel.Fatal, _logger.Name, target);
_logger.Log(typeof(Log), eventInfo);
}

public static void Error(string target) {
LogEventInfo eventInfo = new LogEventInfo(LogLevel.Error, _logger.Name, target);
var eventInfo = new LogEventInfo(LogLevel.Error, _logger.Name, target);
_logger.Log(typeof(Log), eventInfo);
}

public static void Warn(string target) {
LogEventInfo eventInfo = new LogEventInfo(LogLevel.Warn, _logger.Name, target);
var eventInfo = new LogEventInfo(LogLevel.Warn, _logger.Name, target);
_logger.Log(typeof(Log), eventInfo);
}

public static void Info(string target) {
LogEventInfo eventInfo = new LogEventInfo(LogLevel.Info, _logger.Name, target);
var eventInfo = new LogEventInfo(LogLevel.Info, _logger.Name, target);
_logger.Log(typeof(Log), eventInfo);
}

public static void Debug(string target) {
#if DEBUG
LogEventInfo eventInfo = new LogEventInfo(LogLevel.Debug, _logger.Name, target);
var eventInfo = new LogEventInfo(LogLevel.Debug, _logger.Name, target);
_logger.Log(typeof(Log), eventInfo);
#endif
}

public static void Trace(string target) {
#if DEBUG
LogEventInfo eventInfo = new LogEventInfo(LogLevel.Trace, _logger.Name, target);
var eventInfo = new LogEventInfo(LogLevel.Trace, _logger.Name, target);
_logger.Log(typeof(Log), eventInfo);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion MidiPlayer/PlayList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PlayList {
///////////////////////////////////////////////////////////////////////////////////////////////
// Fields [nouns, noun phrases]

List<string> _targetList = new List<string>();
List<string> _targetList = new();

int _idx;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace MidiPlayer.Test {
using MidiPlayer;

namespace MidiPlayerTest {
[TestClass()]
public class PlayListTests {
#nullable enable
[TestMethod()]
public void NextTest1() {
var target = new PlayList();
PlayList target = new();
target.Add("file1.mid");
target.Add("file2.mid");
target.Add("file3.mid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using System.Reflection;

namespace MidiPlayer {
namespace MidiPlayerTest {
/// <summary>
/// PrivateObject for MSTest
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace MidiPlayer.SoundFont.Tests {
using MidiPlayer.SoundFont;

namespace MidiPlayerTest.SoundFont {
[TestClass()]
public class SoundFontInfoTests {
#nullable enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using System.Collections.Generic;

namespace MidiPlayer.Midi.Test {
namespace MidiPlayerTest.Midi {
[TestClass()]
public class StandardMidiFileTests {
#nullable enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using System.Threading.Tasks;
using static System.Threading.Thread;

namespace MidiPlayer.Test {
using MidiPlayer;

namespace MidiPlayerTest {
[TestClass()]
public class SynthTests {
#nullable enable
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit dae2f31

Please sign in to comment.