Skip to content

Commit fdefc2a

Browse files
committed
Tau - further work expanding link API
Now supports disabling and enabling link as well as auto-updating a cached BPM value which removes the need to round-trip an API query for every BPM lookup (API queries can be forced though)
1 parent c91ef10 commit fdefc2a

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

app/server/erlang/tau/src/tau_server/tau_server_api.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ loop(State) ->
170170
send_to_link({link_rpc, UUID, get_num_peers}, State),
171171
?MODULE:loop(State);
172172

173+
174+
{cmd, ["/link-disable"]=Cmd} ->
175+
debug_cmd(Cmd),
176+
send_to_link({link_disable}, State),
177+
?MODULE:loop(State);
178+
179+
{cmd, ["/link-enable"]=Cmd} ->
180+
debug_cmd(Cmd),
181+
send_to_link({link_enable}, State),
182+
?MODULE:loop(State);
183+
184+
173185
{cmd, Cmd} ->
174186
log("Unknown command:: ~p~n", [Cmd]),
175187
?MODULE:loop(State)

app/server/erlang/tau/src/tau_server/tau_server_cue.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ loop(State) ->
121121
cue_port := CuePort,
122122
in_socket := InSocket} ->
123123
forward_internal_cue(CueHost, CuePort, InSocket, "/link/tempo-change", [Tempo]),
124+
send_api_tempo_update(CueHost, CuePort, InSocket, Tempo),
124125
?MODULE:loop(State);
125126
_ ->
126127
debug("Link cue forwarding disabled - ignored tempo change ~n", []),
@@ -324,6 +325,12 @@ send_api_reply(State, UUID, Args) ->
324325
send_udp(InSocket, CueHost, CuePort, Bin),
325326
ok.
326327

328+
send_api_tempo_update(CueHost, CuePort, InSocket, Tempo) ->
329+
Bin = osc:encode(["/link-tempo-change", "erlang", Tempo]),
330+
send_udp(InSocket, CueHost, CuePort, Bin),
331+
debug("sending link tempo update [~p] to ~p:~p~n", [Tempo, CueHost, CuePort]),
332+
ok.
333+
327334
forward_internal_cue(CueHost, CuePort, InSocket, Path, Args) ->
328335
Bin = osc:encode(["/internal-cue", "erlang", Path | Args]),
329336
send_udp(InSocket, CueHost, CuePort, Bin),

app/server/erlang/tau/src/tau_server/tau_server_link.erl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ loop(State) ->
8989
maps:get(cue_server, State) ! {link, stop},
9090
?MODULE:loop(State);
9191

92+
93+
{link_disable} ->
94+
log("Disabling link~n", []),
95+
sp_link:enable(false),
96+
?MODULE:loop(State);
97+
98+
{link_enable} ->
99+
log("Enabling link~n", []),
100+
sp_link:enable(true),
101+
?MODULE:loop(State);
102+
92103
{link_rpc, UUID, get_current_time} ->
93104
Time = sp_link:get_current_time_microseconds(),
94105
log("Received link rpc current_time [~p]~n", [Time]),

app/server/ruby/lib/sonicpi/tau_api.rb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def initialize(ports, handlers)
3838
@link_time = nil
3939
@local_time = nil
4040

41+
@tempo = nil
4142
Thread.new do
4243
initialize_link_info!
4344
end
@@ -68,11 +69,17 @@ def link_current_time
6869

6970
def link_current_and_local_time
7071
api_rpc("/link-get-curent-and-local-time") << Time.now
71-
end
7272

73-
def link_tempo
74-
res = api_rpc("/link-get-tempo")
75-
res[0]
73+
def link_tempo(force_api_call=false)
74+
if force_api_call
75+
res = api_rpc("/link-get-tempo")
76+
@tempo = res[0]
77+
return res[0]
78+
elsif @tempo
79+
return @tempo
80+
else
81+
@tempo = link_tempo(true)
82+
end
7683
end
7784

7885
def link_num_peers
@@ -90,6 +97,16 @@ def link_get_time_at_beat(beat, quantum)
9097
res[0]
9198
end
9299

100+
101+
102+
def link_disable
103+
@tau_comms.send("/link-disable")
104+
end
105+
106+
def link_enable
107+
@tau_comms.send("/link-enable")
108+
end
109+
93110
def midi_system_start!
94111
@tau_comms.send("/stop-start-midi-cues", 1)
95112
end
@@ -137,6 +154,12 @@ def initialize_link_info!
137154
end
138155

139156
def add_incoming_api_handlers!
157+
@tau_comms.add_method("/link-tempo-change") do |args|
158+
gui_id = args[0]
159+
tempo = args[1].to_f
160+
@tempo = tempo
161+
end
162+
140163
@tau_comms.add_method("/midi-ins") do |args|
141164
gui_id = args[0]
142165
ins = args[1..-1]

0 commit comments

Comments
 (0)