Skip to content

Commit 2b99fe4

Browse files
committed
Spider - minor code cleanup
1 parent 32dd60f commit 2b99fe4

File tree

3 files changed

+66
-85
lines changed

3 files changed

+66
-85
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class EventHistory
159159

160160
attr_accessor :event_matchers
161161

162-
def initialize(all_threads=nil, thread_mut=nil)
162+
def initialize
163163
@trim_history = true
164164
@min_history_size = 20
165165
@history_depth = 32

app/server/ruby/lib/sonicpi/lang/sound.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ def self.included(base)
125125
@mod_sound_studio.start
126126
end
127127

128-
@life_hooks.on_killed do |job_id, payload|
129-
# Do nothing for now
130-
end
128+
# @life_hooks.on_killed do |job_id, payload|
129+
# # Do nothing for now
130+
# end
131131

132-
@life_hooks.on_completed do |job_id, payload|
133-
# Do nothing for now
134-
end
132+
# @life_hooks.on_completed do |job_id, payload|
133+
# # Do nothing for now
134+
# end
135135

136136
@life_hooks.on_all_completed do |silent=false|
137137
@mod_sound_studio.pause(silent)

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

Lines changed: 59 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,6 @@ def __with_preserved_spider_time_and_beat(&blk)
239239
### End - Spider Time Management functions
240240
###
241241

242-
243-
def __register_internal_cue_event(address, args)
244-
p = 0
245-
d = 0
246-
b = 0
247-
m = 60
248-
@register_cue_event_lambda.call(Time.now, p, @system_init_thread_id, d, b, m, address, args, 0)
249-
end
250-
251-
def __register_external_osc_cue_event(time, host, port, address, args)
252-
address = "/#{address}" unless address.start_with?("/")
253-
address = "/osc:#{host}:#{port}#{address}"
254-
p = 0
255-
d = 0
256-
b = 0
257-
m = 60
258-
@register_cue_event_lambda.call(Time.now, p, @system_init_thread_id, d, b, m, address, args, 0)
259-
end
260-
261242
def __gui_heartbeat(id)
262243
t = Time.now.freeze
263244
@gui_heartbeats[id] = t
@@ -545,13 +526,10 @@ def __midi_system_stop(silent=false)
545526
end
546527

547528
def __update_midi_ins(ins)
548-
desc = ins.join("\n")
549-
__msg_queue.push({:type => :midi_in_ports, :val => desc})
529+
550530
end
551531

552532
def __update_midi_outs(outs)
553-
desc = outs.join("\n")
554-
__msg_queue.push({:type => :midi_out_ports, :val => desc})
555533
end
556534

557535
def __osc_flush!
@@ -588,11 +566,10 @@ def __replace_buffer_idx(idx, content)
588566
__msg_queue.push({type: "replace-buffer-idx", buffer_idx: idx, val: content, line: 0, index: 0, first_line: 0})
589567
end
590568

591-
def __run_buffer_idx(idx)
592-
idx = idx.to_i
593-
content = content.to_s
594-
__msg_queue.push({type: "run-buffer-idx", buffer_idx: idx})
595-
end
569+
# def __run_buffer_idx(idx)
570+
# idx = idx.to_i
571+
# __msg_queue.push({type: "run-buffer-idx", buffer_idx: idx})
572+
# end
596573

597574
def __add_completion(k, text, point_line_offset=0, point=0)
598575
@snippets[k] = [text, point_line_offset, point]
@@ -608,10 +585,6 @@ def __snippet_completion?(text)
608585
return nil
609586
end
610587

611-
def __indent_lines(buf)
612-
613-
end
614-
615588

616589
def __buffer_indent_lines(workspace_id, buf, start_line, finish_line, point_line, point_index)
617590
__buffer_complete_snippet_or_indent_lines(workspace_id, buf, start_line, finish_line, point_line, point_index, false)
@@ -877,24 +850,23 @@ def __set_default_user_thread_locals!
877850
end
878851

879852
def __spider_eval(code, info={})
880-
id = @job_counter.next
881-
882-
silent = info.fetch(:silent, false)
883-
884853
# skip __nosave lines for error reporting
885854
firstline = 1
886855
firstline -= code.lines.to_a.take_while{|l| l.include? "#__nosave__"}.count
887856
start_t_prom = Promise.new
888857
info[:workspace] = 'eval' unless info[:workspace]
889-
890858
info[:workspace].freeze
891859
info.freeze
892860

861+
silent = info.fetch(:silent, false)
862+
893863
job_in_thread = nil
864+
id = @job_counter.next
865+
894866
job = Thread.new do
895867
Thread.current.priority = 20
896868
begin
897-
num_running_jobs = reg_job(id, Thread.current)
869+
num_running_jobs = register_job!(id, Thread.current)
898870
__system_thread_locals.set_local :sonic_pi_local_thread_group, "job-#{id}"
899871
__system_thread_locals.set_local :sonic_pi_spider_thread_id_path, ThreadId.new(id)
900872
__system_thread_locals.set_local :sonic_pi_spider_num_threads_spawned, 0
@@ -958,6 +930,7 @@ def __spider_eval(code, info={})
958930
end
959931
end
960932
end
933+
961934
@user_jobs.add_job(id, job, info)
962935

963936
Thread.new do
@@ -1245,7 +1218,7 @@ def __in_thread(*opts, &block)
12451218

12461219
private
12471220

1248-
def reg_job(job_id, t)
1221+
def register_job!(job_id, t)
12491222
num_current_jobs = 0
12501223
@job_subthread_mutex.synchronize do
12511224
@job_subthreads[job_id] = Set.new
@@ -1406,60 +1379,33 @@ class Runtime
14061379
def initialize(ports, msg_queue, user_methods)
14071380

14081381
@ports = ports
1382+
@msg_queue = msg_queue
1383+
@user_methods = user_methods
1384+
14091385
@git_hash = __extract_git_hash
14101386
gh_short = @git_hash ? "-#{@git_hash[0, 5]}" : ""
14111387
@settings = Config::Settings.new(Paths.system_cache_store_path)
1412-
# @scsynth_clobber_args = @audio_settings.scsynth_opts_override
1413-
# @scsynth_opts = @audio_settings.scsynth_opts
14141388
@version = Version.new(4, 0, 0, "beta1")
14151389
@server_version = __server_version
14161390
@life_hooks = LifeCycleHooks.new
1417-
@msg_queue = msg_queue
14181391
@cue_events = IncomingEvents.new
14191392
@job_counter = Counter.new(-1) # Start counting jobs from 0
14201393
@job_subthreads = {}
14211394
@job_main_threads = {}
14221395
@named_subthreads = {}
14231396
@job_subthread_mutex = Mutex.new
1397+
@osc_cue_server_mutex = Mutex.new
14241398
@user_jobs = Jobs.new
1425-
@user_methods = user_methods
14261399
@global_start_time = Time.now
14271400
@session_id = SecureRandom.uuid
14281401
@snippets = {}
1429-
1430-
1431-
external_osc_cue_handler = lambda do |time, ip, port, address, args|
1432-
__register_external_osc_cue_event(time, ip, port, address, args)
1433-
end
1434-
1435-
internal_cue_handler = lambda do |path, args|
1436-
__register_internal_cue_event(path, args)
1437-
end
1438-
1439-
updated_midi_ins_handler = lambda do |ins|
1440-
__update_midi_ins(ins)
1441-
end
1442-
1443-
updated_midi_outs_handler = lambda do |outs|
1444-
__update_midi_outs(outs)
1445-
end
1446-
1447-
@tau_api = TauAPI.new(ports,
1448-
{
1449-
external_osc_cue: external_osc_cue_handler,
1450-
internal_cue: internal_cue_handler,
1451-
updated_midi_ins: updated_midi_ins_handler,
1452-
updated_midi_outs: updated_midi_outs_handler
1453-
})
1454-
1455-
@system_state = EventHistory.new(@job_subthreads, @job_subthread_mutex)
1456-
@user_state = EventHistory.new(@job_subthreads, @job_subthread_mutex)
1457-
@event_history = EventHistory.new(@job_subthreads, @job_subthread_mutex)
1402+
@system_state = EventHistory.new
1403+
@user_state = EventHistory.new
1404+
@event_history = EventHistory.new
14581405
@system_init_thread_id = ThreadId.new(-1)
1459-
osc_cue_server_thread_id = ThreadId.new(-2)
1460-
@system_state.set 0, 0, osc_cue_server_thread_id, 0, 0, 60, :sched_ahead_time, default_sched_ahead_time
14611406
@gui_cue_log_idxs = Counter.new
1462-
@osc_cue_server_mutex = Mutex.new
1407+
@gui_heartbeats = {}
1408+
@gui_last_heartbeat = nil
14631409

14641410
@register_cue_event_lambda = lambda do |t, p, i, d, b, m, address, args, sched_ahead_time=0|
14651411
t = t.to_r
@@ -1490,15 +1436,48 @@ def initialize(ports, msg_queue, user_methods)
14901436
end
14911437
end
14921438

1493-
# TODO Add support for TCP
1439+
external_osc_cue_handler = lambda do |time, ip, port, address, args|
1440+
address = "/#{address}" unless address.start_with?("/")
1441+
address = "/osc:#{host}:#{port}#{address}"
1442+
p = 0
1443+
d = 0
1444+
b = 0
1445+
m = 60
1446+
@register_cue_event_lambda.call(Time.now, p, @system_init_thread_id, d, b, m, address, args, 0)
1447+
end
1448+
1449+
internal_cue_handler = lambda do |path, args|
1450+
p = 0
1451+
d = 0
1452+
b = 0
1453+
m = 60
1454+
@register_cue_event_lambda.call(Time.now, p, @system_init_thread_id, d, b, m, address, args, 0)
1455+
end
1456+
1457+
updated_midi_ins_handler = lambda do |ins|
1458+
desc = ins.join("\n")
1459+
__msg_queue.push({:type => :midi_in_ports, :val => desc})
1460+
end
1461+
1462+
updated_midi_outs_handler = lambda do |outs|
1463+
desc = outs.join("\n")
1464+
__msg_queue.push({:type => :midi_out_ports, :val => desc})
1465+
end
1466+
1467+
@tau_api = TauAPI.new(ports,
1468+
{
1469+
external_osc_cue: external_osc_cue_handler,
1470+
internal_cue: internal_cue_handler,
1471+
updated_midi_ins: updated_midi_ins_handler,
1472+
updated_midi_outs: updated_midi_outs_handler
1473+
})
14941474

1495-
@gui_heartbeats = {}
1496-
@gui_last_heartbeat = nil
14971475
begin
14981476
@gitsave = GitSave.new(Paths.project_path)
14991477
rescue
15001478
@gitsave = nil
15011479
end
1480+
15021481
@save_queue = SizedQueue.new(20)
15031482

15041483
@save_t = Thread.new do
@@ -1520,6 +1499,8 @@ def initialize(ports, msg_queue, user_methods)
15201499
end
15211500
end
15221501

1502+
@system_state.set 0, 0, ThreadId.new(-2), 0, 0, 60, :sched_ahead_time, default_sched_ahead_time
1503+
15231504
__info "Welcome to Sonic Pi #{version}", 1
15241505

15251506
__info "Running on Ruby v#{RUBY_VERSION}"

0 commit comments

Comments
 (0)