From 3296b7d66244556f5331e8486a167b453368b414 Mon Sep 17 00:00:00 2001 From: Hiroyuki Adachi Date: Tue, 18 Oct 2022 18:59:27 +0900 Subject: [PATCH 1/3] refactor: #1 keeping codes clean. --- Meowziq/Core/Generator.cs | 30 +++++++++++++------------ Meowziq/Core/Mixer.cs | 46 +++++++++++++++++++++----------------- Meowziq/Core/Note.cs | 1 - Meowziq/Core/Phrase.cs | 47 ++++++++++++++++++--------------------- Meowziq/Core/Player.cs | 6 ++--- Meowziq/Utils.cs | 2 +- Meowziq/Value/Data.cs | 8 +++---- 7 files changed, 71 insertions(+), 69 deletions(-) diff --git a/Meowziq/Core/Generator.cs b/Meowziq/Core/Generator.cs index 1592e94..0341106 100644 --- a/Meowziq/Core/Generator.cs +++ b/Meowziq/Core/Generator.cs @@ -63,7 +63,7 @@ public void ApplyNote(int start_tick, int beat_count, List span_list, Para char text = param.TextCharArray[I6beat_index.Idx]; if (param.IsMatch(text)) { Span span = span_list[I6beat_index.SpanIndex]; // 16beat 4個で1拍進む - int[] note_num_array = (new int[7]).Select(x => -1).ToArray(); // ノートNo 配列を -1 で初期化: 後ではじく為 + int[] note_num_array = (new int[7]).Select(selector: x => -1).ToArray(); // ノートNo 配列を -1 で初期化: 後ではじく為 if (param.IsNote) { // "note", "auto" 記述 note_num_array[0] = ToNote( span.Key, span.Degree, span.KeyMode, span.SpanMode, text.Int32(), param.AutoNote @@ -91,10 +91,12 @@ public void ApplyNote(int start_tick, int beat_count, List span_list, Para gate.ApplyPre(pre_string: pre.ToString()); } } - if (param.Exp.HasPost) { // TODO: post設定があれば ロングノート + if (param.Exp.HasPost) { + // TODO: to a long note if has a post parameter. } int tick = gate.PreLength + start_tick + To16beatLength(I6beat_index.Idx); - note_num_array.Where(x => x != -1).ToList().ForEach(x => + // adds a Note object to Item. + note_num_array.Where(predicate: x => x != -1).ToList().ForEach(action: x => add(tick: tick, note: new Note(tick: tick, num: x + param.Interval, gate: gate.Value, velo: 104, pre_count: gate.PreCount)) ); } @@ -110,7 +112,7 @@ public void ApplyDrumNote(int start_tick, int beat_count, Param param) { if (param.IsMatch(text)) { Gete gate = new(); if (param.Exp.HasPre) { // pre設定があれば シンコペーション - var pre = param.Exp.PreCharArray[I6beat_index.Idx]; + char pre = param.Exp.PreCharArray[I6beat_index.Idx]; if (param.Exp.IsMatchPre(pre)) { gate.ApplyPre(pre_string: pre.ToString()); } @@ -172,8 +174,8 @@ public void ApplyInfo(int start_tick, int beat_count, List span_list) { /// converts all notes into the specified range. /// int[] applyRange(int[] target, Range range) { - var new_array = new int[target.Length]; - for (var index = 0; index < target.Length; index++) { + int[] new_array = new int[target.Length]; + for (int index = 0; index < target.Length; index++) { if (target[index] < range.Min) { new_array[index] = target[index] + 12; } else if (target[index] > range.Max) { new_array[index] = target[index] - 12; } else { new_array[index] = target[index]; } @@ -318,6 +320,8 @@ class Index { int _index_for_16beat; // 16beatを4回数える用 + int _index, _span_index; + #endregion /////////////////////////////////////////////////////////////////////////////////////////// @@ -326,7 +330,7 @@ class Index { public Index(int beat_count) { _beat_count = beat_count; _index_for_16beat = 0; - SpanIndex = 0; + _span_index = 0; } #endregion @@ -338,13 +342,11 @@ public Index(int beat_count) { /// 16beat の index 値 /// public int Idx { - get; - private set; + get => _index; } public int SpanIndex { - get; - private set; + get => _span_index; } /// @@ -352,7 +354,7 @@ public int SpanIndex { /// public bool HasNext { get { - if (Idx < To16beatCount(_beat_count)) { + if (_index < To16beatCount(_beat_count)) { return true; // index 値がパターンの16beatの長さ以下なら true } return false; @@ -365,11 +367,11 @@ public bool HasNext { #region public Methods [verb] public void Increment() { - Idx++; // increments 16 beats. + _index++; // increments 16 beats. _index_for_16beat++; // 16beat のカウントをインクリメント if (_index_for_16beat == 4) { // 4カウント溜まったら _index_for_16beat = 0; - SpanIndex++; // Span index をインクリメント MEMO: 1拍のこと + _span_index++; // Span index をインクリメント MEMO: 1拍のこと } // TODO: 必要なのは1小節をカウントすることとそのindex値 } diff --git a/Meowziq/Core/Mixer.cs b/Meowziq/Core/Mixer.cs index 04d8ab6..52dea9b 100644 --- a/Meowziq/Core/Mixer.cs +++ b/Meowziq/Core/Mixer.cs @@ -214,6 +214,12 @@ public class Fader { /////////////////////////////////////////////////////////////////////////////////////////// // static Fields + string _type, _name; + + int _program_num, _player_program_num, _vol; + + Pan _pan; + bool _mute = false; /////////////////////////////////////////////////////////////////////////////////////////// @@ -223,36 +229,36 @@ public class Fader { /// NOTE: Player と紐づけ /// public string Type { - get; set; + get => _type; set => _type = value; } /// /// NOTE: Pattern と紐づけ /// public string Name { - get; set; + get => _name; set => _name = value; } /// /// NOTE: mixer.json に設定された値 /// public int ProgramNum { - get; set; + get => _program_num; set => _program_num = value; } /// /// NOTE: player.json に設定された値 /// public int PlayerProgramNum { - get; set; + get => _player_program_num; set => _player_program_num = value; } public int Vol { - get; set; + get => _vol; set => _vol = value; } public Pan Pan { - get; set; + get => _pan; set => _pan = value; } public bool Mute { @@ -264,25 +270,25 @@ public bool Mute { public static Fader NoVaule(string type) { return new Fader() { - Type = type, - Name = "undefined", - ProgramNum = -1, - PlayerProgramNum = -1, - Vol = -1, - Pan = Pan.Undefined, - Mute = false + _type = type, + _name = "undefined", + _program_num = -1, + _player_program_num = -1, + _vol = -1, + _pan = Pan.Undefined, + _mute = false }; } public static Fader Default(string type) { return new Fader() { - Type = type, - Name = "default", - ProgramNum = -1, - PlayerProgramNum = -1, - Vol = 100, - Pan = Pan.Center, - Mute = false + _type = type, + _name = "default", + _program_num = -1, + _player_program_num = -1, + _vol = 100, + _pan = Pan.Center, + _mute = false }; } } diff --git a/Meowziq/Core/Note.cs b/Meowziq/Core/Note.cs index ffd273f..b921fd5 100644 --- a/Meowziq/Core/Note.cs +++ b/Meowziq/Core/Note.cs @@ -40,7 +40,6 @@ public Note(int tick, int num, int gate, int velo, int pre_count = 0) { _gate = gate; _velo = velo; _pre_count = pre_count; - Log.Trace($"tick: {tick}"); } /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Meowziq/Core/Phrase.cs b/Meowziq/Core/Phrase.cs index 04dc9b9..91acd78 100644 --- a/Meowziq/Core/Phrase.cs +++ b/Meowziq/Core/Phrase.cs @@ -33,7 +33,7 @@ public class Phrase { /////////////////////////////////////////////////////////////////////////////////////////////// // Fields - string _type; + string _type, _name, _base; Data _data; // json から読み込んだデータを格納 @@ -61,16 +61,15 @@ public string Type { } public string Name { - get; set; + get => _name; set => _name = value; } public string Base { - get; set; + get => _base; set => _base = value; } public Data Data { - get => _data; - set => _data = value; + get => _data; set => _data = value; } /// @@ -78,14 +77,12 @@ public Data Data { /// public string Range { set { - if (value is null) { - return; - } - var range_text = value; + if (value is null) { return; } + string range_text = value; if (!range_text.Contains(":")) { throw new ArgumentException("invalid range format."); } - var range_array = range_text.Split(':'); + string[] range_array = range_text.Split(':'); if (range_array.Length != 2) { throw new ArgumentException("invalid range format."); } @@ -129,7 +126,7 @@ public List AllNote { if (!Type.ToLower().Contains("drum")) { // ドラム以外 TODO: これで良いか確認 optimize(); // 最適化する } - return _note_item.SelectMany(x => x.Value).Select(x => x).ToList(); + return _note_item.SelectMany(selector: x => x.Value).Select(selector: x => x).ToList(); // FIXME: 二重? } } @@ -151,16 +148,16 @@ public void Build(int tick, Pattern pattern) { /// FIXME: バグあり ⇒ シンコペーションは小節の頭だけ許可する? /// public void RemoveBy(Note target) { - var tick1 = target.Tick; - var note_list1 = _note_item.Get(tick1); - note_list1 = note_list1.Where(x => !(!x.HasPre && x.Tick == tick1)).ToList(); // 優先ノートではなく tick が同じものを削除 // FIXME: ドラムは音毎? - _note_item.SetBy(tick1, note_list1); + int tick1 = target.Tick; + List note_list1 = _note_item.Get(key: tick1); + note_list1 = note_list1.Where(predicate: x => !(!x.HasPre && x.Tick == tick1)).ToList(); // 優先ノートではなく tick が同じものを削除 // FIXME: ドラムは音毎? + _note_item.SetBy(key: tick1, value: note_list1); if (target.PreCount > 1) { // さらにシンコぺの設定値が2の場合 - var tick2 = target.Tick + Length.Of16beat.Int32(); - var note_list2 = _note_item.Get(tick2); + int tick2 = target.Tick + Length.Of16beat.Int32(); + List note_list2 = _note_item.Get(tick2); if (note_list2 != null) { note_list2 = note_list2.Where(x => !(!x.HasPre && x.Tick == tick2)).ToList(); // さらに被る16音符を削除 - _note_item.SetBy(tick2, note_list2); + _note_item.SetBy(key: tick2, value: note_list2); } } } @@ -172,8 +169,8 @@ public void RemoveBy(Note target) { /// Note データを生成します /// protected void onBuild(int tick, Pattern pattern) { - var generator = Generator.GetInstance(note_item: _note_item); - var data_type = defineDataType(); + Generator generator = Generator.GetInstance(note_item: _note_item); + DataType data_type = defineDataType(); switch (data_type) { case DataType.Mono: { @@ -188,8 +185,8 @@ protected void onBuild(int tick, Pattern pattern) { } break; case DataType.Multi: - var string_array = _data.Auto ? _data.AutoArray : _data.NoteArray; - for (var index = 0; index < string_array.Length; index++) { + string[] string_array = _data.Auto ? _data.AutoArray : _data.NoteArray; + for (int index = 0; index < string_array.Length; index++) { Param param = new( note: new Value.Note(string_array[index], _data.OctArray[index]), exp: new Value.Exp(_data.PreArray[index], _data.PostArray[index]), @@ -236,9 +233,9 @@ protected void onBuild(int tick, Pattern pattern) { /// + current の シンコペ Note <= 判定済み /// void optimize() { - var note_list = _note_item.SelectMany(x => x.Value).Select(x => x).ToList(); - foreach (var stop_note in note_list.Where(x => x.HasPre)) { // 優先ノートのリスト - foreach (var note in note_list) { // このフレーズの全てのノートの中で + List note_list = _note_item.SelectMany(x => x.Value).Select(x => x).ToList(); // ??? 二重? + foreach (Note stop_note in note_list.Where(x => x.HasPre)) { // 優先ノートのリスト + foreach (Note note in note_list) { // このフレーズの全てのノートの中で if (note.Tick == stop_note.Tick) { // 優先ノートと発音タイミングがかぶったら RemoveBy(note); // ノートを削除 } diff --git a/Meowziq/Core/Player.cs b/Meowziq/Core/Player.cs index 484aee6..780d4f0 100644 --- a/Meowziq/Core/Player.cs +++ b/Meowziq/Core/Player.cs @@ -75,13 +75,11 @@ public DrumKit DrumKit { } public string Type { - get => _type; - set => _type = value; + get => _type; set => _type = value; } public List PhraseList { - get => _phrase_list; - set => _phrase_list = value; + get => _phrase_list; set => _phrase_list = value; } /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Meowziq/Utils.cs b/Meowziq/Utils.cs index 64005b4..ea4042a 100644 --- a/Meowziq/Utils.cs +++ b/Meowziq/Utils.cs @@ -81,7 +81,7 @@ public static int ToNote(Key key, Degree degree, Mode key_mode, Mode span_mode, scale7 = scale7By(key: Key.Enum.Parse(degree_note), key_mode: mode); // そのルート音の旋法スケールを取得 } else { // キーの旋法を自動判定してそちらから取得 Mode key_mode_current = ToKeyMode(key: key, degree: degree, key_mode: key_mode, span_mode: mode); - if (!key_mode_current.ToString().Equals("Undefined")) { // 旋法が判定出来れば + if (key_mode_current is not Mode.Undefined) { // 旋法が判定出来れば scale7 = scale7By(key: key, key_mode: key_mode_current); // 判定した曲の旋法を取得 } } diff --git a/Meowziq/Value/Data.cs b/Meowziq/Value/Data.cs index c6b315a..a80f92c 100644 --- a/Meowziq/Value/Data.cs +++ b/Meowziq/Value/Data.cs @@ -379,7 +379,7 @@ public Note() { } public Note(string text, int oct) { - Text = text; + _text = PhraseValue(target: text); _oct = oct; } @@ -455,8 +455,8 @@ public class Seque { string _text; /// - /// + same concept as "chord" notated numbers. - /// + how many chords? + /// + same concept as "chord" notated numbers.
+ /// + how many chords?
///
int _stack; // * before development. @@ -513,7 +513,7 @@ public static int ToGateValue(string target) { //if (target.Equals(">")) { return 95 /*(int) (127 * 75 * 0.01f)*/; } // ≒95 //if (target.Equals("*")) { return 64 /*(int) (127 * 50 * 0.01f)*/; } // ≒64 //if (target.Equals("+")) { return 32 /*(int) (127 * 25 * 0.01f)*/; } // ≒32 - return 30;//0; + return 30;//0; // FIXME: this value is tick!!!!!! } } From ab2e42d1a491dcc5f0ccf30c1619655a12a69f38 Mon Sep 17 00:00:00 2001 From: Hiroyuki Adachi Date: Tue, 18 Oct 2022 19:43:37 +0900 Subject: [PATCH 2/3] refactor: #1 keeping codes clean. --- .../MainForm.Designer.cs | 34 +++++++++---------- .../FormMain.cs => Meowziq.Win64/MainForm.cs | 10 +++--- .../MainForm.resx | 0 .../Meowziq.Win64.csproj | 0 {Meowziq.View => Meowziq.Win64}/NLog.config | 0 {Meowziq.View => Meowziq.Win64}/Program.cs | 4 +-- Meowziq.sln | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) rename Meowziq.View/FormMain.Designer.cs => Meowziq.Win64/MainForm.Designer.cs (97%) rename Meowziq.View/FormMain.cs => Meowziq.Win64/MainForm.cs (98%) rename Meowziq.View/FormMain.resx => Meowziq.Win64/MainForm.resx (100%) rename Meowziq.View/Meowziq.View.csproj => Meowziq.Win64/Meowziq.Win64.csproj (100%) rename {Meowziq.View => Meowziq.Win64}/NLog.config (100%) rename {Meowziq.View => Meowziq.Win64}/Program.cs (94%) diff --git a/Meowziq.View/FormMain.Designer.cs b/Meowziq.Win64/MainForm.Designer.cs similarity index 97% rename from Meowziq.View/FormMain.Designer.cs rename to Meowziq.Win64/MainForm.Designer.cs index 3ad62b5..82fcb60 100644 --- a/Meowziq.View/FormMain.Designer.cs +++ b/Meowziq.Win64/MainForm.Designer.cs @@ -1,5 +1,5 @@ -namespace Meowziq.View { - partial class FormMain { +namespace Meowziq.Win64 { + partial class MainForm { /// /// 必要なデザイナー変数です。 /// @@ -25,7 +25,7 @@ protected override void Dispose(bool disposing) { private void InitializeComponent() { this._sequence = new Sanford.Multimedia.Midi.Sequence(); this._sequencer = new Sanford.Multimedia.Midi.Sequencer(); - this._piano_control = new Sanford.Multimedia.Midi.UI.PianoControl(); + this._pianocontrol = new Sanford.Multimedia.Midi.UI.PianoControl(); this._button_play = new System.Windows.Forms.Button(); this._button_stop = new System.Windows.Forms.Button(); this._button_load = new System.Windows.Forms.Button(); @@ -71,17 +71,17 @@ private void InitializeComponent() { this._sequencer.Sequence = this._sequence; this._sequencer.ChannelMessagePlayed += new System.EventHandler(this.sequencer_ChannelMessagePlayed); // - // _piano_control + // _pianocontrol // - this._piano_control.HighNoteID = 109; - this._piano_control.Location = new System.Drawing.Point(15, 322); - this._piano_control.LowNoteID = 21; - this._piano_control.Name = "_piano_control"; - this._piano_control.NoteOnColor = System.Drawing.Color.SkyBlue; - this._piano_control.Size = new System.Drawing.Size(915, 140); - this._piano_control.TabIndex = 4; - this._piano_control.TabStop = false; - this._piano_control.Text = "pianoControl"; + this._pianocontrol.HighNoteID = 109; + this._pianocontrol.Location = new System.Drawing.Point(15, 322); + this._pianocontrol.LowNoteID = 21; + this._pianocontrol.Name = "_piano_control"; + this._pianocontrol.NoteOnColor = System.Drawing.Color.SkyBlue; + this._pianocontrol.Size = new System.Drawing.Size(915, 140); + this._pianocontrol.TabIndex = 4; + this._pianocontrol.TabStop = false; + this._pianocontrol.Text = "pianoControl"; // // _button_play // @@ -429,7 +429,7 @@ private void InitializeComponent() { this._numericupdown_repeat_end.TabIndex = 32; this._numericupdown_repeat_end.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // - // FormMain + // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -439,7 +439,7 @@ private void InitializeComponent() { this.Controls.Add(this._label_repeat_end); this.Controls.Add(this._label_repeat_begin); this.Controls.Add(this._numericupdown_repeat_begin); - this.Controls.Add(this._piano_control); + this.Controls.Add(this._pianocontrol); this.Controls.Add(this._label_modulation_text); this.Controls.Add(this._label_modulation); this.Controls.Add(this._label_mode); @@ -466,7 +466,7 @@ private void InitializeComponent() { this.Controls.Add(this._button_load); this.Controls.Add(this._button_stop); this.Controls.Add(this._button_play); - this.Name = "FormMain"; + this.Name = "MainForm"; this.Text = "© STUDIO MeowToon"; ((System.ComponentModel.ISupportInitialize)(this._numericupdown_repeat_begin)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this._numericupdown_repeat_end)).EndInit(); @@ -479,7 +479,7 @@ private void InitializeComponent() { private Sanford.Multimedia.Midi.Sequence _sequence; private Sanford.Multimedia.Midi.Sequencer _sequencer; - private Sanford.Multimedia.Midi.UI.PianoControl _piano_control; + private Sanford.Multimedia.Midi.UI.PianoControl _pianocontrol; private System.Windows.Forms.Button _button_play; private System.Windows.Forms.Button _button_stop; private System.Windows.Forms.Button _button_load; diff --git a/Meowziq.View/FormMain.cs b/Meowziq.Win64/MainForm.cs similarity index 98% rename from Meowziq.View/FormMain.cs rename to Meowziq.Win64/MainForm.cs index 9906eb0..59183b8 100644 --- a/Meowziq.View/FormMain.cs +++ b/Meowziq.Win64/MainForm.cs @@ -30,7 +30,7 @@ using static Meowziq.Env; using static Meowziq.Utils; -namespace Meowziq.View { +namespace Meowziq.Win64 { /// /// main form of the application. /// @@ -38,7 +38,7 @@ namespace Meowziq.View { /// exclusive control. /// /// h.adachi (STUDIO MeowToon) - public partial class FormMain : Form { + public partial class MainForm : Form { /////////////////////////////////////////////////////////////////////////////////////////////// // Fields @@ -52,7 +52,7 @@ public partial class FormMain : Form { /////////////////////////////////////////////////////////////////////////////////////////////// // Constructor - public FormMain() { + public MainForm() { InitializeComponent(); _midi = new(); // creates a midi manager class. } @@ -162,7 +162,7 @@ void sequencer_ChannelMessagePlayed(object sender, ChannelMessageEventArgs e) { }); // MEMO: Parallel.ForEach was slow. list.ForEach(action: x => { if (x.MidiChannel != 9 && x.MidiChannel != 1) { // FIXME: exclude sequences is provisional. - _piano_control.Send(message: x); // shows in piano roll except for drums. + _pianocontrol.Send(message: x); // shows in piano roll except for drums. } if (x.MidiChannel == 2) { //Log.Trace($"Data1: {x.Data1} Data2: {x.Data2}"); @@ -404,7 +404,7 @@ MethodInvoker updateDisplay(State.Item16beat item) { MethodInvoker resetDisplay() { return () => { Enumerable.Range(start: 0, count: 88).ToList().ForEach( - action: x => _piano_control.Send(message: new ChannelMessage(command: ChannelCommand.NoteOff, midiChannel: 1, data1: x, data2: 0)) + action: x => _pianocontrol.Send(message: new ChannelMessage(command: ChannelCommand.NoteOff, midiChannel: 1, data1: x, data2: 0)) ); _label_play.ForeColor = _label_modulation.ForeColor = DimGray; _textbox_beat.Text = _textbox_meas.Text = "0"; diff --git a/Meowziq.View/FormMain.resx b/Meowziq.Win64/MainForm.resx similarity index 100% rename from Meowziq.View/FormMain.resx rename to Meowziq.Win64/MainForm.resx diff --git a/Meowziq.View/Meowziq.View.csproj b/Meowziq.Win64/Meowziq.Win64.csproj similarity index 100% rename from Meowziq.View/Meowziq.View.csproj rename to Meowziq.Win64/Meowziq.Win64.csproj diff --git a/Meowziq.View/NLog.config b/Meowziq.Win64/NLog.config similarity index 100% rename from Meowziq.View/NLog.config rename to Meowziq.Win64/NLog.config diff --git a/Meowziq.View/Program.cs b/Meowziq.Win64/Program.cs similarity index 94% rename from Meowziq.View/Program.cs rename to Meowziq.Win64/Program.cs index a054410..0957856 100644 --- a/Meowziq.View/Program.cs +++ b/Meowziq.Win64/Program.cs @@ -16,7 +16,7 @@ using System; using System.Windows.Forms; -namespace Meowziq.View { +namespace Meowziq.Win64 { /// /// the application. /// @@ -29,7 +29,7 @@ static class Program { static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FormMain()); + Application.Run(new MainForm()); } } } diff --git a/Meowziq.sln b/Meowziq.sln index a131ea6..8f8d228 100644 --- a/Meowziq.sln +++ b/Meowziq.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.30413.136 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meowziq", "Meowziq\Meowziq.csproj", "{73E21602-E5FB-46BD-8FBC-C18E72E79089}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meowziq.View", "Meowziq.View\Meowziq.View.csproj", "{5365817E-0BC2-4444-BFFB-30EC3577D510}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meowziq.Win64", "Meowziq.Win64\Meowziq.Win64.csproj", "{5365817E-0BC2-4444-BFFB-30EC3577D510}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MeowziqTest", "MeowziqTest\MeowziqTest.csproj", "{020B8C9F-E580-4CC0-A3F5-693D6D50B9BB}" EndProject From 6347d3462fb4f6afd51cdd4609754690600a9628 Mon Sep 17 00:00:00 2001 From: Hiroyuki Adachi Date: Tue, 18 Oct 2022 20:49:09 +0900 Subject: [PATCH 3/3] feat: #23 selected the MIDI output devices. --- Meowziq.Midi/Midi/Manager.cs | 33 +++++++++++++++++++++++------ Meowziq.Win64/MainForm.Designer.cs | 34 +++++++++++++++++++++++++++--- Meowziq.Win64/MainForm.cs | 18 +++++++++++++++- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/Meowziq.Midi/Midi/Manager.cs b/Meowziq.Midi/Midi/Manager.cs index e5c5965..0b69697 100644 --- a/Meowziq.Midi/Midi/Manager.cs +++ b/Meowziq.Midi/Midi/Manager.cs @@ -36,18 +36,23 @@ public class Manager { /////////////////////////////////////////////////////////////////////////////////////////////// // Constructor - public Manager() { + Manager() { _out_device_name_list = MidiDevice.GetOutDeviceName(); - _out_device = new OutputDevice(_out_device_id); + loadDevice(); + } + + /// + /// returns an initialized instance. + /// + public static Manager GetInstance() { + return new Manager(); } /////////////////////////////////////////////////////////////////////////////////////////////// // Properties [noun, adjective] public OutputDevice OutDevice { - get { - return _out_device; - } + get => _out_device; } public List OutDeviceName { @@ -55,7 +60,23 @@ public List OutDeviceName { } public int OutDeviceId { - set => _out_device_id = value; + set { + _out_device_id = value; + Log.Info($"midi # of devs: {_out_device_id}"); + loadDevice(); + } + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // private Methods [verb] + + void loadDevice() { + if (_out_device is not null) { + _out_device.Reset(); + _out_device.Close(); + _out_device.Dispose(); + } + _out_device = new OutputDevice(_out_device_id); } } diff --git a/Meowziq.Win64/MainForm.Designer.cs b/Meowziq.Win64/MainForm.Designer.cs index 82fcb60..6c2aa1c 100644 --- a/Meowziq.Win64/MainForm.Designer.cs +++ b/Meowziq.Win64/MainForm.Designer.cs @@ -54,8 +54,10 @@ private void InitializeComponent() { this._label_modulation_text = new System.Windows.Forms.Label(); this._label_repeat_begin = new System.Windows.Forms.Label(); this._label_repeat_end = new System.Windows.Forms.Label(); + this._label_midi_out = new System.Windows.Forms.Label(); this._numericupdown_repeat_begin = new System.Windows.Forms.NumericUpDown(); this._numericupdown_repeat_end = new System.Windows.Forms.NumericUpDown(); + this._combobox_midi_out = new System.Windows.Forms.ComboBox(); this._folderbrowserdialog = new System.Windows.Forms.FolderBrowserDialog(); ((System.ComponentModel.ISupportInitialize)(this._numericupdown_repeat_begin)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this._numericupdown_repeat_end)).BeginInit(); @@ -76,7 +78,7 @@ private void InitializeComponent() { this._pianocontrol.HighNoteID = 109; this._pianocontrol.Location = new System.Drawing.Point(15, 322); this._pianocontrol.LowNoteID = 21; - this._pianocontrol.Name = "_piano_control"; + this._pianocontrol.Name = "_pianocontrol"; this._pianocontrol.NoteOnColor = System.Drawing.Color.SkyBlue; this._pianocontrol.Size = new System.Drawing.Size(915, 140); this._pianocontrol.TabIndex = 4; @@ -395,7 +397,7 @@ private void InitializeComponent() { this._label_repeat_begin.Name = "_label_repeat_begin"; this._label_repeat_begin.Size = new System.Drawing.Size(88, 19); this._label_repeat_begin.TabIndex = 29; - this._label_repeat_begin.Text = "REPE BEG"; + this._label_repeat_begin.Text = "REPT BEG"; // // _label_repeat_end // @@ -407,7 +409,19 @@ private void InitializeComponent() { this._label_repeat_end.Name = "_label_repeat_end"; this._label_repeat_end.Size = new System.Drawing.Size(89, 19); this._label_repeat_end.TabIndex = 30; - this._label_repeat_end.Text = "REPE END"; + this._label_repeat_end.Text = "REPT END"; + // + // _label_midi_out + // + this._label_midi_out.AutoSize = true; + this._label_midi_out.Font = new System.Drawing.Font("Meiryo UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this._label_midi_out.ForeColor = System.Drawing.Color.White; + this._label_midi_out.Location = new System.Drawing.Point(235, 271); + this._label_midi_out.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this._label_midi_out.Name = "_label_midi_out"; + this._label_midi_out.Size = new System.Drawing.Size(90, 19); + this._label_midi_out.TabIndex = 33; + this._label_midi_out.Text = "MIDI OUT"; // // _numericupdown_repeat_begin // @@ -429,12 +443,24 @@ private void InitializeComponent() { this._numericupdown_repeat_end.TabIndex = 32; this._numericupdown_repeat_end.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // + // _combobox_midi_out + // + this._combobox_midi_out.Font = new System.Drawing.Font("Meiryo UI", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this._combobox_midi_out.FormattingEnabled = true; + this._combobox_midi_out.Location = new System.Drawing.Point(341, 260); + this._combobox_midi_out.Name = "_combobox_midi_out"; + this._combobox_midi_out.Size = new System.Drawing.Size(433, 37); + this._combobox_midi_out.TabIndex = 34; + this._combobox_midi_out.SelectedIndexChanged += new System.EventHandler(this._combobox_midi_out_SelectedIndexChanged); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); this.ClientSize = new System.Drawing.Size(945, 483); + this.Controls.Add(this._combobox_midi_out); + this.Controls.Add(this._label_midi_out); this.Controls.Add(this._numericupdown_repeat_end); this.Controls.Add(this._label_repeat_end); this.Controls.Add(this._label_repeat_begin); @@ -508,8 +534,10 @@ private void InitializeComponent() { private System.Windows.Forms.Label _label_modulation_text; private System.Windows.Forms.Label _label_repeat_begin; private System.Windows.Forms.Label _label_repeat_end; + private System.Windows.Forms.Label _label_midi_out; private System.Windows.Forms.NumericUpDown _numericupdown_repeat_begin; private System.Windows.Forms.NumericUpDown _numericupdown_repeat_end; + private System.Windows.Forms.ComboBox _combobox_midi_out; private System.Windows.Forms.FolderBrowserDialog _folderbrowserdialog; } } diff --git a/Meowziq.Win64/MainForm.cs b/Meowziq.Win64/MainForm.cs index 59183b8..0ba164b 100644 --- a/Meowziq.Win64/MainForm.cs +++ b/Meowziq.Win64/MainForm.cs @@ -53,8 +53,11 @@ public partial class MainForm : Form { // Constructor public MainForm() { + const int MIDI_OUT_DEFAULT = 0; InitializeComponent(); - _midi = new(); // creates a midi manager class. + _midi = Manager.GetInstance(); // creates a midi manager class. + _midi.OutDeviceName.ForEach(action: x => _combobox_midi_out.Items.Add(item: x)); + _combobox_midi_out.SelectedIndex = MIDI_OUT_DEFAULT; } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -137,6 +140,19 @@ async void buttonConvert_Click(object sender, EventArgs e) { } } + /// + /// selects MIDI output device. + /// + private void _combobox_midi_out_SelectedIndexChanged(object sender, EventArgs e) { + try { + _midi.OutDeviceId = _combobox_midi_out.SelectedIndex; + } + catch (Exception ex) { + MessageBox.Show(text: ex.Message, caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Stop); + Log.Error(ex.Message); + } + } + /// /// throws MIDI data to the device. ///