Skip to content

Commit

Permalink
Merge pull request #25 from hiroxpepe/develop
Browse files Browse the repository at this point in the history
feat: #23 selected the MIDI output devices.
  • Loading branch information
hiroxpepe authored Oct 18, 2022
2 parents 6cd39da + 6347d34 commit d8996ba
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 103 deletions.
33 changes: 27 additions & 6 deletions Meowziq.Midi/Midi/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,47 @@ public class Manager {
///////////////////////////////////////////////////////////////////////////////////////////////
// Constructor

public Manager() {
Manager() {
_out_device_name_list = MidiDevice.GetOutDeviceName();
_out_device = new OutputDevice(_out_device_id);
loadDevice();
}

/// <summary>
/// returns an initialized instance.
/// </summary>
public static Manager GetInstance() {
return new Manager();
}

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

public OutputDevice OutDevice {
get {
return _out_device;
}
get => _out_device;
}

public List<string> OutDeviceName {
get => _out_device_name_list;
}

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);
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions Meowziq.View/FormMain.cs → Meowziq.Win64/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
using static Meowziq.Env;
using static Meowziq.Utils;

namespace Meowziq.View {
namespace Meowziq.Win64 {
/// <summary>
/// main form of the application.
/// </summary>
/// <todo>
/// exclusive control.
/// </todo>
/// <author>h.adachi (STUDIO MeowToon)</author>
public partial class FormMain : Form {
public partial class MainForm : Form {

///////////////////////////////////////////////////////////////////////////////////////////////
// Fields
Expand All @@ -52,9 +52,12 @@ public partial class FormMain : Form {
///////////////////////////////////////////////////////////////////////////////////////////////
// Constructor

public FormMain() {
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;
}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -137,6 +140,19 @@ async void buttonConvert_Click(object sender, EventArgs e) {
}
}

/// <summary>
/// selects MIDI output device.
/// </summary>
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);
}
}

/// <summary>
/// throws MIDI data to the device.
/// </summary>
Expand All @@ -162,7 +178,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}");
Expand Down Expand Up @@ -404,7 +420,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";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions Meowziq.View/Program.cs → Meowziq.Win64/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System;
using System.Windows.Forms;

namespace Meowziq.View {
namespace Meowziq.Win64 {
/// <summary>
/// the application.
/// </summary>
Expand All @@ -29,7 +29,7 @@ static class Program {
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
Application.Run(new MainForm());
}
}
}
2 changes: 1 addition & 1 deletion Meowziq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions Meowziq/Core/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void ApplyNote(int start_tick, int beat_count, List<Span> 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
Expand Down Expand Up @@ -91,10 +91,12 @@ public void ApplyNote(int start_tick, int beat_count, List<Span> 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))
);
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -172,8 +174,8 @@ public void ApplyInfo(int start_tick, int beat_count, List<Span> span_list) {
/// converts all notes into the specified range.
/// </summary>
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]; }
Expand Down Expand Up @@ -318,6 +320,8 @@ class Index {

int _index_for_16beat; // 16beatを4回数える用

int _index, _span_index;

#endregion

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -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
Expand All @@ -338,21 +342,19 @@ public Index(int beat_count) {
/// 16beat の index 値
/// </summary>
public int Idx {
get;
private set;
get => _index;
}

public int SpanIndex {
get;
private set;
get => _span_index;
}

/// <summary>
/// この Pattern に次の 16beat が存在するかどうか
/// </summary>
public bool HasNext {
get {
if (Idx < To16beatCount(_beat_count)) {
if (_index < To16beatCount(_beat_count)) {
return true; // index 値がパターンの16beatの長さ以下なら true
}
return false;
Expand All @@ -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値
}

Expand Down
Loading

0 comments on commit d8996ba

Please sign in to comment.