30
30
% % are forwarded directly without starting a timer.
31
31
-define (NODELAY_LIMIT , 1 ).
32
32
33
- -import (tau_server_util ,
34
- [log /1 , log /2 , debug /2 , debug /3 ]).
35
-
36
-
37
33
% % Bundle Commands
38
34
% % ===============
39
35
@@ -80,7 +76,7 @@ init(Parent, CueServer, MIDIServer, LinkServer) ->
80
76
APIPort = application :get_env (? APPLICATION , api_port , undefined ),
81
77
DaemonPort = application :get_env (? APPLICATION , daemon_port , undefined ),
82
78
83
- io : format (" ~n "
79
+ logger : info (" ~n "
84
80
" +--------------------------------------+~n "
85
81
" This is the Sonic Pi API Server ~n "
86
82
" Powered by Erlang ~s ~n "
@@ -99,7 +95,7 @@ init(Parent, CueServer, MIDIServer, LinkServer) ->
99
95
100
96
101
97
102
- debug (2 , " listening for API commands on socket: ~p~n " ,
98
+ logger : debug (" listening for API commands on socket: ~p~n " ,
103
99
[try erlang :port_info (APISocket ) catch _ :_ -> undefined end ]),
104
100
State = #{parent => Parent ,
105
101
api_socket => APISocket ,
@@ -114,7 +110,7 @@ init(Parent, CueServer, MIDIServer, LinkServer) ->
114
110
loop (State ) ->
115
111
receive
116
112
{tcp , Socket , Data } ->
117
- debug (3 , " api server got TCP on ~p :~p~n " , [Socket , Data ]),
113
+ logger : debug (" api server got TCP on ~p :~p~n " , [Socket , Data ]),
118
114
? MODULE :loop (State );
119
115
120
116
{timeout , Timer , {call , Server , Msg , Tracker }} ->
@@ -123,10 +119,10 @@ loop(State) ->
123
119
? MODULE :loop (State );
124
120
125
121
{udp , APISocket , Ip , Port , Bin } ->
126
- debug (3 , " api server got UDP on ~p :~p~n " , [Ip , Port ]),
122
+ logger : debug (" api server got UDP on ~p :~p~n " , [Ip , Port ]),
127
123
case osc :decode (Bin ) of
128
124
{cmd , [" /ping" ]} ->
129
- debug (" sending! /pong to ~p ~p ~n " , [Ip , Port ]),
125
+ logger : debug (" sending! /pong to ~p ~p ~n " , [Ip , Port ]),
130
126
PongBin = osc :encode ([" /pong" ]),
131
127
ok = gen_udp :send (APISocket , Ip , Port , PongBin ),
132
128
? MODULE :loop (State );
@@ -135,7 +131,7 @@ loop(State) ->
135
131
? MODULE :loop (State );
136
132
137
133
{bundle , Time , X } ->
138
- debug (" got bundle for time ~f~n " , [Time ]),
134
+ logger : debug (" got bundle for time ~f~n " , [Time ]),
139
135
NewState = do_bundle (Time , X , State ),
140
136
? MODULE :loop (NewState );
141
137
@@ -218,7 +214,7 @@ loop(State) ->
218
214
? MODULE :loop (State );
219
215
220
216
{cmd , Cmd } ->
221
- log (" Unknown OSC command:: ~p~n " , [Cmd ]),
217
+ logger : error (" Unknown OSC command:: ~p~n " , [Cmd ]),
222
218
? MODULE :loop (State );
223
219
224
220
{system , From , Request } ->
@@ -227,7 +223,7 @@ loop(State) ->
227
223
maps :get (parent , State ),
228
224
? MODULE , [], State );
229
225
Any ->
230
- log (" API Server got unexpected message: ~p~n " , [Any ]),
226
+ logger : error (" API Server got unexpected message: ~p~n " , [Any ]),
231
227
? MODULE :loop (State )
232
228
end .
233
229
@@ -243,7 +239,7 @@ send_to_cue(Message, State) ->
243
239
ok .
244
240
245
241
debug_cmd ([Cmd |Args ]) ->
246
- debug (" command: ~s ~p~n " , [Cmd , Args ]).
242
+ logger : debug (" command: ~s ~p~n " , [Cmd , Args ]).
247
243
248
244
do_bundle (Time , [{_ ,Bin }|T ], State ) ->
249
245
NewState =
@@ -261,11 +257,11 @@ do_bundle(Time, [{_,Bin}|T], State) ->
261
257
{cmd , [" /link-set-tempo-tagged" , Tag , Tempo ]} ->
262
258
schedule_link (Time , Tag , State , {link_set_tempo , Tempo });
263
259
Other ->
264
- log (" Unexpected bundle content:~p~n " , [Other ]),
260
+ logger : error (" Unexpected bundle content:~p~n " , [Other ]),
265
261
State
266
262
catch
267
263
Class :Term :Trace ->
268
- log (" Error decoding OSC: ~p~n~p :~p~n~p~n " ,
264
+ logger : error (" Error decoding OSC: ~p~n~p :~p~n~p~n " ,
269
265
[Bin , Class , Term , Trace ]),
270
266
State
271
267
end ,
@@ -284,11 +280,11 @@ schedule_internal_call(Time, Tag, State, Server, Msg) ->
284
280
% % at that time, the message will be quietly dropped
285
281
SchedMsg = {call , Server , Msg , Tracker },
286
282
Timer = erlang :start_timer (MsDelay , self (), SchedMsg ),
287
- debug (2 , " start (MIDI) timer of ~w ms for time ~f~n " , [MsDelay , Time ]),
283
+ logger : debug (" start (MIDI) timer of ~w ms for time ~f~n " , [MsDelay , Time ]),
288
284
tau_server_tracker :track (Timer , Time , Tracker );
289
285
true ->
290
286
Server ! Msg ,
291
- debug (2 , " Directly sent scheduled call~n " , [])
287
+ logger : debug (" Directly sent scheduled call~n " , [])
292
288
end ,
293
289
NewState .
294
290
@@ -313,7 +309,7 @@ tracker_pid(Tag, State) ->
313
309
{Pid , State };
314
310
error ->
315
311
Pid = tau_server_tracker :start_link (Tag ),
316
- debug (" start new tracker process for tag \" ~s \" ~n " , [Tag ]),
312
+ logger : debug (" start new tracker process for tag \" ~s \" ~n " , [Tag ]),
317
313
{Pid , State #{tag_map := maps :put (Tag , Pid , TagMap )}}
318
314
end .
319
315
0 commit comments