Orca-c
Orca-c copied to clipboard
Proposal: Commander (`$`) operator and utils.
Preface:
The other day I was watching this tutorial featured in the OrcaJS repo, and I found out that adjusting the BPM programmatically (as seen here) wasn't an option, so I decided to try and implement that, along with some of the other features from the commander interface.
I haven't programmed anything in C beyond some "hello world"
stuff (I come from a JS background) and this PR is the result of reverse engineering the really comprehensible code written in this repo + some web search :smile: .
Changes:
Menu
- Added menu option under help for the
Crtl + G
command to show operators.
Implemented Orca commander
interface:
State (state.h
):
- Abstracted values that could be altered via commands to a new struct called
State
*, it savesbpm
,tick_num
,is_playing
and*oosc_dev
(that one is still a TODO). - Implemented this struct through the whole app.
* This abstraction was necessary to change is_playing
via reference pointer (without abstracting the whole Ged
struct). It could still be implemented without struct nesting, changing the type of is_playing
to int
and leaving everything inside of the Ged
struct intact (this could maybe favor performance, but I don't know how much the performance is affected currently by passing a struct vs passing each value individually by reference).
Commander (commander.h
, commander.c
, sim.h
, sim.c
, cli_main.c
, symisc.c
):
- Implemented
parse_command(Glyph command, State state)
method. This implementation adds the following commands:play
,run
,stop
,bpm:num
,frame:num
,rewind:num
andskip:num
. It usesstrtok
to obtain tokens,strcmp
to compare strings andstrtoul
to parse number values. - Added commander operation, it copies the current buffer with the same values as the UDP parser (this should also be revised) and passes the copy as a command to the
parse_command
method. -
orca_run
now takesstate
as the only param related tobpm
,tick_num
,is_playing
andoosc_dev
.
tool:
- Prioritize compilation of
commander.c
to avoid linking errors.
Caveats and considerations:
- Perhaps nesting structs isn't the best option for performance in devices that have smaller computing power, but I currently have no means to test this (also addressed in
State
abstraction). This can be mitigated easily removing said abstraction and passing every single value by reference, - Some stuff is dependent and copied directly from the udp operator code, perhaps it needs some considerations in regards to how commands are parsed (as it copies 16 chars from the buffer in the copy method).
- Maybe some stuff could be abstracted into macros and I'm not considering it.
- There's some issues regarding advancing single frames: sometimes this triggers a double BANG (don't know if it relates to these changes or is a separate issue, but it's simple to view when using the
skip
command).