Skip to content

Commit

Permalink
Tau - fix API bundle handling
Browse files Browse the repository at this point in the history
The format of the parsed OSC bundles changed when support for handling OSC bundles as incoming cues was added - but didn't get reflected in the internal API!?!
  • Loading branch information
samaaron committed Oct 21, 2024
1 parent 298838a commit 4839a25
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions app/server/beam/tau/src/tau_server/tau_server_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ loop(State) ->
end,
?MODULE:loop(State);

{bundle, Time, X} ->
logger:debug("got bundle for time ~f", [Time]),
NewState = do_bundle(Time, X, State),
{bundle, Time, Bins} ->
NewState = lists:foldl(
fun(X, AccState) ->
do_bundle(Time, X, AccState)
end,
State,
Bins
),
?MODULE:loop(NewState);

% {cmd, ["/hydra_eval", Code]=Cmd} ->
Expand Down Expand Up @@ -314,39 +319,33 @@ send_to_cue(Message, State) ->
debug_cmd([Cmd|Args]) ->
logger:debug("command: ~s ~p", [Cmd, Args]).

do_bundle(Time, [{_,Bin}|T], State) ->
do_bundle(Time, Args, State) ->
% logger:info("Decoding bundle content:~p", [Args]),
NewState =
try osc:decode(Bin) of
{cmd, ["/send-after", Host, Port, OSC]} ->
case Args of
["/send-after", Host, Port, OSC] ->
schedule_cmd(Time, "default", State, {send_osc, Host, Port, OSC});
{cmd, ["/send-after-tagged", Tag, Host, Port, OSC]} ->
["/send-after-tagged", Tag, Host, Port, OSC] ->
schedule_cmd(Time, Tag, State, {send_osc, Host, Port, OSC});
{cmd, ["/midi-at", MIDI]} ->
["/midi-at", MIDI] ->
schedule_midi(Time, "default", State, {send_midi, MIDI});
{cmd, ["/midi-at-tagged", Tag, MIDI]} ->
["/midi-at-tagged", Tag, MIDI] ->
schedule_midi(Time, Tag, State, {send_midi, MIDI});
{cmd, ["/link-set-tempo", Tempo]} ->
["/link-set-tempo", Tempo] ->
schedule_link(Time, "default", State, {link_set_tempo, Tempo});
{cmd, ["/link-set-tempo-tagged", Tag, Tempo]} ->
["/link-set-tempo-tagged", Tag, Tempo] ->
schedule_link(Time, Tag, State, {link_set_tempo, Tempo});
{cmd, ["/link-set-is-playing", Enabled]} ->
["/link-set-is-playing", Enabled] ->
schedule_link(Time, "default", State, {link_set_is_playing, Enabled});
{cmd, ["/link-set-is-playing-tagged", Tag, Enabled]} ->
["/link-set-is-playing-tagged", Tag, Enabled] ->
schedule_link(Time, Tag, State, {link_set_is_playing, Enabled});
{cmd, ["/hydra_eval", Code]} ->
["/hydra_eval", Code] ->
schedule_internal_call(Time, "default", State, self(), {cmd, ["/hydra_eval", Code]});
Other ->
logger:error("Unexpected bundle content:~p", [Other]),
State
catch
Class:Term:Trace ->
logger:error("Error decoding OSC: ~p~n~p:~p~n~p",
[Bin, Class, Term, Trace]),
logger:error("Unexpected bundle content:~p", Other),
State
end,
do_bundle(Time, T, NewState);
do_bundle(_Time, [], State) ->
State.
NewState.

schedule_internal_call(Time, Tag, State, Server, Msg) ->
Delay = Time - osc:now(),
Expand Down

0 comments on commit 4839a25

Please sign in to comment.