Skip to content

Commit

Permalink
Merge pull request #24 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 17, 2022
2 parents 568d7b6 + db9e2a1 commit 6cd39da
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 31 deletions.
76 changes: 75 additions & 1 deletion Meowziq.Midi/Midi/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using System.Runtime.InteropServices;
using Sanford.Multimedia.Midi;

namespace Meowziq.Midi {
Expand All @@ -27,12 +29,15 @@ public class Manager {

OutputDevice _out_device;

int _out_device_id = 0; // TODO: to be able to choose.
int _out_device_id = 0;

List<string> _out_device_name_list;

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

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

Expand All @@ -44,5 +49,74 @@ public OutputDevice OutDevice {
return _out_device;
}
}

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

public int OutDeviceId {
set => _out_device_id = value;
}
}

/// <summary>
/// Midi device class.
/// </summary>
public static class MidiDevice {

///////////////////////////////////////////////////////////////////////////////////////////////
// public static Methods [verb]

/// <summary>
/// gets MIDI out device names.
/// </summary>
/// <returns></returns>
public static List<string> GetOutDeviceName() {
List<string> out_device_name_list = new();
uint midi_out_num_devs = midiOutGetNumDevs();
Log.Info($"midi # of devs: {midi_out_num_devs}");
for (uint index = 0; index < midi_out_num_devs; index++) {
MidiOutCaps midi_out_caps = new MidiOutCaps();
midiOutGetDevCaps(uDevID: index, pmic: out midi_out_caps, cbmic: Marshal.SizeOf(typeof(MidiOutCaps)));
Log.Info($"#{index}: {midi_out_caps.szPname}");
out_device_name_list.Add(item: midi_out_caps.szPname);
}
return out_device_name_list;
}

///////////////////////////////////////////////////////////////////////////////////////////////
// Win32API

[StructLayout(LayoutKind.Sequential)]
public struct MidiInCaps {
public ushort wMid;
public ushort wPid;
public uint vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szPname;
public uint dwSupport;
}

[StructLayout(LayoutKind.Sequential)]
public struct MidiOutCaps {
public ushort wMid;
public ushort wPid;
public uint vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szPname;
public uint dwSupport;
}

[DllImport("winmm.dll")]
extern static uint midiInGetNumDevs();

[DllImport("winmm.dll")]
extern static uint midiOutGetNumDevs();

[DllImport("winmm.dll")]
extern static uint midiInGetDevCaps(uint uDevID, out MidiInCaps pmic, int cbmic);

[DllImport("winmm.dll")]
extern static uint midiOutGetDevCaps(uint uDevID, out MidiOutCaps pmic, int cbmic);
}
}
6 changes: 3 additions & 3 deletions Meowziq/Core/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ public void ApplySequeNote(int start_tick, int beat_count, List<Span> span_list,
if (param.Seque.Range is not null) {
note_num = applyRange(target: new int[] { note_num }, range: param.Seque.Range)[0]; // TODO: applyRange の単音 ver
}
if (param.HasTextCharArray) { // TODO: 判定方法の改善
if (param.HasTextCharArray) {
char text = param.TextCharArray[I6beat_index.Idx];
if (param.Seque.Text.HasValue() && param.IsMatch(text)) {
int tick = start_tick + To16beatLength(index: I6beat_index.Idx);
add(tick: tick, note: new Note(tick: tick, num: note_num, gate: Seque.ToGate(target: text.ToString()), velo: 104));
add(tick: tick, note: new Note(tick: tick, num: note_num, gate: Seque.ToGateValue(target: text.ToString()), velo: 104));
}
} else {
int tick = start_tick + To16beatLength(index: I6beat_index.Idx);
Expand Down Expand Up @@ -188,7 +188,7 @@ int[] applyRange(int[] target, Range range) {
/// adds a Note to the Item object with the tick.
/// </summary>
void add(int tick, Note note) {
_note_item.Add(tick, note);
_note_item.Add(key: tick, value: note);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Meowziq/Core/Mixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static Fader AddFader {
return;
}
_current_fader_map[$"{value.Type}:{value.Name}"] = value;
_previous_fader_map[value.Type] = Fader.NoVaule(value.Type);
_previous_fader_map[value.Type] = Fader.NoVaule(type: value.Type);
_use = true; // Fader を追加された、つまり mixier.json が存在する
}
}
Expand Down
12 changes: 9 additions & 3 deletions Meowziq/Core/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ public void Build(int tick, bool smf = false) {
// テンポ・曲名設定 FIXME: 全プレイヤーが設定しているが?
State.TempoAndName = (_song.Tempo, _song.Name);

// 初期設定
if (tick is 0) { // TODO: player.json の音色を設定
Mixer<T>.ApplyVaule(0, _midi_ch, Type, "intro", _program_num); // TODO: 必要? and "intro" ?
/// <summary>
/// adds initial parameters for Mixer object.
/// </summary>
/// <note>
/// sets instrument name in player.json.
/// </note>
if (tick is 0) {
string first_pattern_name = _song.AllSection.SelectMany(x => x.AllPattern).ToList().Where(x => x.Name is not "count").First().Name;
Mixer<T>.ApplyVaule(tick: 0, midi_ch: _midi_ch, type: Type, name: "intro", program_num: _program_num);
}

// Note データ作成のループ
Expand Down
36 changes: 13 additions & 23 deletions Meowziq/Value/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,9 @@ public class Seque {
// Fields

/// <summary>
/// "gate" notated.
/// </summary>
/// <memo_jp>
/// + 120 が16分音符、30:60:90:120 で4音価にするか?
/// + 100%音価は効果が薄いので必要ない
/// + "-" は無効の文字としてのみ使用されるべき
/// + "+*>" の3文字で設定
/// + -: 0%
/// + +: 25%
/// + *: 50%
/// + >: 75%
/// </memo_jp>
string _text; // gate 設定用
string _text;

/// <memo>
/// + same concept as "chord" notated numbers.
Expand All @@ -473,16 +464,19 @@ public class Seque {
/// + the concept of Range is easier to handle if it is one octave. <br/>
/// + isn't it easier to handle with a default range? <br/>
/// </memo>
Range _range; // * before development.
Range _range;

/// <summary>
/// whether use or not.
/// </summary>
bool _use;

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

public Seque() {
Text = string.Empty;
_stack = 3;
_text = string.Empty;
_stack = 3; // * before development.
_use = false;
}

Expand Down Expand Up @@ -515,15 +509,11 @@ public bool Use {
/// <summary>
/// converts the text mark to the note value.
/// </summary>
public static int ToGate(string target) {
if (target.Equals("+")) {
return 30;
} else if (target.Equals("*")) {
return 60;
} else if (target.Equals(">")) {
return 90;
}
return 0;
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;
}
}

Expand Down

0 comments on commit 6cd39da

Please sign in to comment.