Skip to content

Commit

Permalink
Merge pull request #28 from hiroxpepe/develop
Browse files Browse the repository at this point in the history
refactor: #1 keeping codes clean.
  • Loading branch information
hiroxpepe authored Oct 19, 2022
2 parents 8e73abc + b3b1dbc commit e947726
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 386 deletions.
54 changes: 25 additions & 29 deletions Meowziq.Midi/Midi/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Meowziq.Midi {
/// message class using Sanford.Multimedia.Midi
/// </summary>
/// <fixme>
/// relies on abstraction instead of ChannelMessage.
/// + relies on abstraction instead of ChannelMessage. <br/>
/// </fixme>
/// <author>h.adachi (STUDIO MeowToon)</author>
public static class Message {
Expand All @@ -52,10 +52,10 @@ static Message() {
/// <summary>
/// returns the list of ChannelMessages for the argument tick.
/// </summary>
/// <remarks>
/// returns null if the list does not exist.<br/>
/// run in "Prime" start.
/// </remarks>
/// <note>
/// + returns null if the list does not exist. <br/>
/// + run in "Prime" start. <br/>
/// </note>
public static List<ChannelMessage> GetBy(int tick) {
if (_flag) {
return Prime.Item.Get(key: tick); // TODO: checks for problems.
Expand All @@ -67,9 +67,9 @@ public static List<ChannelMessage> GetBy(int tick) {
/// <summary>
/// whether has the item with the argument tick.
/// </summary>
/// <remarks>
/// run in "Prime" start.
/// </remarks>
/// <note>
/// + run in "Prime" start. <br/>
/// </note>
public static bool Has(int tick) {
if (_flag) {
return Prime.Item.Select(x => x.Key).Max() > tick;
Expand Down Expand Up @@ -107,9 +107,9 @@ public static void ApplyTick(int tick, Action<int> load) {
/// <summary>
/// applies program_num as ChannelMessage.
/// </summary>
/// <remarks>
/// program change.
/// </remarks>
/// <note>
/// + program change. <br/>
/// </note>
public static void ApplyProgramChange(int tick, int midi_ch, int program_num ) {
add(tick: tick, message: new ChannelMessage(ChannelCommand.ProgramChange, midi_ch, program_num, 127));
}
Expand Down Expand Up @@ -141,9 +141,9 @@ public static void ApplyMute(int tick, int midi_ch, bool mute) {
/// <summary>
/// applies note as ChannelMessage.
/// </summary>
/// <remarks>
/// run in "Second" start.
/// </remarks>
/// <note>
/// + run in "Second" start. <br/>
/// </note>
public static void ApplyNote(int tick, int midi_ch, Note note) {
if (!_flag) {
if (note.HasPre) { // note has priority pronunciation,
Expand Down Expand Up @@ -194,9 +194,9 @@ public static void Invert() {
/// <summary>
/// adds a ChannelMessage to the list.
/// </summary>
/// <remarks>
/// run in "Second" start.
/// </remarks>
/// <note>
/// + run in "Second" start. <br/>
/// </note>
static void add(int tick, ChannelMessage message) {
if (!_flag) {
Prime.Item.Add(tick, message);
Expand Down Expand Up @@ -235,26 +235,24 @@ static class Prime {
/// <summary>
/// array for note forced stop.
/// </summary>
static HashSet<int>[] _all_note_off_to_add_array = new HashSet<int>[16];
static HashSet<int>[] _all_note_off_to_add_array = new HashSet<int>[MIDI_TRACK_COUNT];

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

static Prime() {
_all_note_off_to_add_array = _all_note_off_to_add_array.Select(x => x = new HashSet<int>()).ToArray();
_all_note_off_to_add_array = _all_note_off_to_add_array.Select(selector: x => x = new()).ToArray();
}

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

public static Item<ChannelMessage> Item {
get => _item;
set => _item = value;
get => _item; set => _item = value;
}

public static HashSet<int>[] AllNoteOffToAddArray {
get => _all_note_off_to_add_array;
set => _all_note_off_to_add_array = value;
get => _all_note_off_to_add_array; set => _all_note_off_to_add_array = value;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -279,26 +277,24 @@ static class Second {
/// <summary>
/// array for note forced stop.
/// </summary>
static HashSet<int>[] _all_note_off_to_add_array = new HashSet<int>[16];
static HashSet<int>[] _all_note_off_to_add_array = new HashSet<int>[MIDI_TRACK_COUNT];

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

static Second() {
_all_note_off_to_add_array = _all_note_off_to_add_array.Select(x => x = new HashSet<int>()).ToArray();
_all_note_off_to_add_array = _all_note_off_to_add_array.Select(selector: x => x = new()).ToArray();
}

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

public static Item<ChannelMessage> Item {
get => _item;
set => _item = value;
get => _item; set => _item = value;
}

public static HashSet<int>[] AllNoteOffToAddArray {
get => _all_note_off_to_add_array;
set => _all_note_off_to_add_array = value;
get => _all_note_off_to_add_array; set => _all_note_off_to_add_array = value;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
61 changes: 32 additions & 29 deletions Meowziq/Core/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Generator {
}

/// <summary>
/// returns an initialized instance.
/// gets an initialized instance.
/// </summary>
public static Generator GetInstance(Item<Note> note_item) {
return new Generator(note_item);
Expand All @@ -62,30 +62,30 @@ public void ApplyNote(int start_tick, int beat_count, List<Span> span_list, Para
for (Index I6beat_index = new(beat_count); I6beat_index.HasNext; I6beat_index.Increment()) {
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(selector: x => -1).ToArray(); // ノートNo 配列を -1 で初期化: 後ではじく為
if (param.IsNote) { // "note", "auto" 記述
Span span = span_list[I6beat_index.SpanIndex]; // 4 times of 16 beats advance 1 beat.
int[] note_num_array = (new int[7]).Select(selector: x => -1).ToArray(); // initializes an array of notes with -1 : to remove it later.
if (param.IsNote) { // "note", "auto" notated.
note_num_array[0] = ToNote(
span.Key, span.Degree, span.KeyMode, span.SpanMode, text.Int32(), param.AutoNote
key: span.Key, degree: span.Degree, key_mode: span.KeyMode, span_mode: span.SpanMode, number: text.Int32(), auto_note: param.AutoNote
);
} else if (param.IsChord) { // "chord" 記述
} else if (param.IsChord) { // "chord" notated.
note_num_array = ToNoteArray(
span.Key, span.Degree, span.KeyMode, span.SpanMode, text.Int32()
key: span.Key, degree: span.Degree, key_mode: span.KeyMode, span_mode: span.SpanMode, number: text.Int32()
);
note_num_array = applyRange(target: note_num_array, range: param.Chord.Range); // コード展開形の範囲を適用
note_num_array = applyRange(target: note_num_array, range: param.Chord.Range); // applies octave range to affect chord inversions.
}
// check the note value of this sound
Gete gate = new(search_idx: I6beat_index.Idx, beat_count: beat_count);
for (; gate.HasNextSearch; gate.IncrementSearch()) { // +1 は数値文字の分
// creates the length of the note as a Gate object.
Gate gate = new(search_idx: I6beat_index.Idx, beat_count: beat_count);
for (; gate.HasNextSearch; gate.IncrementSearch()) {
char search = param.TextCharArray[gate.SearchIndex];
if (search.Equals('>')) {
gate.IncrementGate(); // 16beat分長さを伸ばす
if (search.Equals('>')) { // has a '>' character in the search result.
gate.IncrementGate(); // extends length by 16 beats.
}
if (!search.Equals('>')) {
break; // '>' が途切れたら終了
break; // has not '>' character in the search result: exits.
}
}
if (param.Exp.HasPre) { // pre設定があれば シンコペーション
if (param.Exp.HasPre) { // has a pre parameter, it's syncopation.
char pre = param.Exp.PreCharArray[I6beat_index.Idx];
if (param.Exp.IsMatchPre(pre)) {
gate.ApplyPre(pre_string: pre.ToString());
Expand All @@ -110,8 +110,8 @@ public void ApplyDrumNote(int start_tick, int beat_count, Param param) {
for (Index I6beat_index = new(beat_count); I6beat_index.HasNext; I6beat_index.Increment()) {
char text = param.TextCharArray[I6beat_index.Idx];
if (param.IsMatch(text)) {
Gete gate = new();
if (param.Exp.HasPre) { // pre設定があれば シンコペーション
Gate gate = new();
if (param.Exp.HasPre) { // has a pre parameter, it's syncopation.
char pre = param.Exp.PreCharArray[I6beat_index.Idx];
if (param.Exp.IsMatchPre(pre)) {
gate.ApplyPre(pre_string: pre.ToString());
Expand All @@ -128,10 +128,10 @@ public void ApplyDrumNote(int start_tick, int beat_count, Param param) {
/// </summary>
public void ApplySequeNote(int start_tick, int beat_count, List<Span> span_list, Param param) {
for (Index I6beat_index = new(beat_count); I6beat_index.HasNext; I6beat_index.Increment()) {
Span span = span_list[I6beat_index.SpanIndex]; // 16beat 4個で1拍進む
int note_num = ToRandomNote(key: span.Key, degree: span.Degree, key_mode: span.KeyMode, span_mode: span.SpanMode); // 16の倍数
Span span = span_list[I6beat_index.SpanIndex]; // 4 times of 16 beats advance 1 beat.
int note_num = ToRandomNote(key: span.Key, degree: span.Degree, key_mode: span.KeyMode, span_mode: span.SpanMode);
if (param.Seque.Range is not null) {
note_num = applyRange(target: new int[] { note_num }, range: param.Seque.Range)[0]; // TODO: applyRange の単音 ver
note_num = applyRange(target: new int[] { note_num }, range: param.Seque.Range)[0]; // TODO: single note ver of applyRange.
}
if (param.HasTextCharArray) {
char text = param.TextCharArray[I6beat_index.Idx];
Expand All @@ -141,7 +141,7 @@ public void ApplySequeNote(int start_tick, int beat_count, List<Span> span_list,
}
} else {
int tick = start_tick + To16beatLength(index: I6beat_index.Idx);
add(tick: tick, note: new Note(tick: tick, num: note_num, gate: 30, velo: 104)); // TODO: デフォルトの Text 記述を持たせればこの分岐は削除出来る:パターンの長さで自動生成
add(tick: tick, note: new Note(tick: tick, num: note_num, gate: 30, velo: 104)); // TODO: can be removed if you have a default Text description. : automatically generated by pattern length.
}
}
}
Expand All @@ -151,10 +151,10 @@ public void ApplySequeNote(int start_tick, int beat_count, List<Span> span_list,
/// </summary>
public void ApplyInfo(int start_tick, int beat_count, List<Span> span_list) {
for (Index I6beat_index = new(beat_count); I6beat_index.HasNext; I6beat_index.Increment()) {
Span span = span_list[I6beat_index.SpanIndex]; // 16beat 4個で1拍進む
int tick = start_tick + To16beatLength(index: I6beat_index.Idx); // 16beat の tick 毎に処理
if (State.HashSet.Add(item: tick)) { // tick につき1度だけ
State.ItemMap.Add(key: tick, value: new State.Item16beat {
Span span = span_list[I6beat_index.SpanIndex]; // 4 times of 16 beats advance 1 beat.
int tick = start_tick + To16beatLength(index: I6beat_index.Idx); // processed every tick of 16 beats.
if (State.HashSet.Add(item: tick)) { // only once per tick.
State.ItemMap.Add(key: tick, value: new State.Item16beat { // a State object is created every 16 beats.
Tick = tick,
Key = span.Key,
Degree = span.Degree,
Expand Down Expand Up @@ -198,12 +198,12 @@ void add(int tick, Note note) {
///////////////////////////////////////////////////////////////////////////////////////////////
#region inner Classes

#region Gete
#region Gate

/// <summary>
/// class that holds note value information.
/// </summary>
class Gete {
class Gate {

///////////////////////////////////////////////////////////////////////////////////////////
#region Const [nouns]
Expand All @@ -222,13 +222,13 @@ class Gete {
///////////////////////////////////////////////////////////////////////////////////////////
#region Constructor

public Gete(int search_idx, int beat_count) {
public Gate(int search_idx, int beat_count) {
_beat_count = beat_count;
_search_index = search_idx + TEXT_VALUE_LENGTH;
_gate_count = _pre_length = _pre_count = 0;
}

public Gete() {
public Gate() {
_gate_count = _pre_length = _pre_count = 0;
}

Expand Down Expand Up @@ -366,6 +366,9 @@ public bool HasNext {
///////////////////////////////////////////////////////////////////////////////////////////
#region public Methods [verb]

/// <summary>
/// increments 16 beats.
/// </summary>
public void Increment() {
_index++; // increments 16 beats.
_index_for_16beat++; // 16beat のカウントをインクリメント
Expand Down
Loading

0 comments on commit e947726

Please sign in to comment.