From e94e3c9f064b0b152679009a3673a3e6c07331b2 Mon Sep 17 00:00:00 2001 From: cancel Date: Fri, 21 Dec 2018 03:07:05 +0900 Subject: [PATCH] Add osc operator '=' --- bank.h | 4 +++- sim.c | 37 ++++++++++++++++++++++++++++++++++++- tui_main.c | 5 ++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/bank.h b/bank.h index 2913a53..4d018cb 100644 --- a/bank.h +++ b/bank.h @@ -50,11 +50,13 @@ typedef struct { U8 bar_divisor; } Oevent_midi; +enum { Oevent_osc_int_count = 4 }; + typedef struct { U8 oevent_type; Glyph glyph; U8 count; - U8 numbers[4]; + U8 numbers[Oevent_osc_int_count]; } Oevent_osc_ints; typedef union { diff --git a/sim.c b/sim.c index c5b6aa4..8d45ddb 100644 --- a/sim.c +++ b/sim.c @@ -383,7 +383,8 @@ Usz usz_clamp(Usz val, Usz min, Usz max) { _('!', keys) \ _('#', comment) \ _('*', bang) \ - _(':', midi) + _(':', midi) \ + _('=', osc) #define ORCA_DUAL_OPERATORS(_) \ _('A', 'a', add) \ @@ -504,6 +505,40 @@ BEGIN_SOLO_PHASE_1(midi) oe->bar_divisor = (U8)usz_clamp(index_of(length_g), 1, Glyphs_index_max); END_PHASE +BEGIN_SOLO_PHASE_0(osc) + BEGIN_ACTIVE_PORTS + PORT(0, -2, IN | HASTE); + PORT(0, -1, IN | HASTE); + Usz len = index_of(PEEK(0, -1)) + 1; + if (len > Oevent_osc_int_count) + len = Oevent_osc_int_count; + for (Usz i = 0; i < len; ++i) { + PORT(0, (Isz)i + 1, IN); + } + END_PORTS +END_PHASE +BEGIN_SOLO_PHASE_1(osc) + STOP_IF_NOT_BANGED; + Glyph g = PEEK(0, -2); + if (g != '.') { + Usz len = index_of(PEEK(0, -1)) + 1; + if (len > Oevent_osc_int_count) + len = Oevent_osc_int_count; + U8 buff[Oevent_osc_int_count]; + for (Usz i = 0; i < len; ++i) { + buff[i] = (U8)index_of(PEEK(0, (Isz)i + 1)); + } + Oevent_osc_ints* oe = + &oevent_list_alloc_item(extra_params->oevent_list)->osc_ints; + oe->oevent_type = (U8)Oevent_type_osc_ints; + oe->glyph = g; + oe->count = (U8)len; + for (Usz i = 0; i < len; ++i) { + oe->numbers[i] = buff[i]; + } + } +END_PHASE + BEGIN_DUAL_PHASE_0(add) REALIZE_DUAL; BEGIN_DUAL_PORTS diff --git a/tui_main.c b/tui_main.c index e02febd..6a56501 100644 --- a/tui_main.c +++ b/tui_main.c @@ -70,6 +70,7 @@ static Glyph_class glyph_class_of(Glyph glyph) { return Glyph_class_movement; case '!': case ':': + case '=': return Glyph_class_lowercase; case '*': return Glyph_class_bang; @@ -96,6 +97,7 @@ static bool is_valid_glyph(Glyph c) { case '*': case ':': case ';': + case '=': case '#': return true; } @@ -540,8 +542,9 @@ void draw_oevent_list(WINDOW* win, Oevent_list const* oevent_list) { } break; case Oevent_type_osc_ints: { Oevent_osc_ints const* eo = &ev->osc_ints; - wprintw(win, "OSC Ints\tname %c\tcount %d", eo->glyph, eo->count, + wprintw(win, "OSC\t%c\tcount: %d ", eo->glyph, eo->count, eo->count); + waddch(win, ACS_VLINE); for (Usz i = 0; i < eo->count; ++i) { wprintw(win, " %d", eo->numbers[i]); }