@@ -239,25 +239,6 @@ def __with_preserved_spider_time_and_beat(&blk)
239
239
### End - Spider Time Management functions
240
240
###
241
241
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
-
261
242
def __gui_heartbeat ( id )
262
243
t = Time . now . freeze
263
244
@gui_heartbeats [ id ] = t
@@ -545,13 +526,10 @@ def __midi_system_stop(silent=false)
545
526
end
546
527
547
528
def __update_midi_ins ( ins )
548
- desc = ins . join ( "\n " )
549
- __msg_queue . push ( { :type => :midi_in_ports , :val => desc } )
529
+
550
530
end
551
531
552
532
def __update_midi_outs ( outs )
553
- desc = outs . join ( "\n " )
554
- __msg_queue . push ( { :type => :midi_out_ports , :val => desc } )
555
533
end
556
534
557
535
def __osc_flush!
@@ -588,11 +566,10 @@ def __replace_buffer_idx(idx, content)
588
566
__msg_queue . push ( { type : "replace-buffer-idx" , buffer_idx : idx , val : content , line : 0 , index : 0 , first_line : 0 } )
589
567
end
590
568
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
596
573
597
574
def __add_completion ( k , text , point_line_offset = 0 , point = 0 )
598
575
@snippets [ k ] = [ text , point_line_offset , point ]
@@ -608,10 +585,6 @@ def __snippet_completion?(text)
608
585
return nil
609
586
end
610
587
611
- def __indent_lines ( buf )
612
-
613
- end
614
-
615
588
616
589
def __buffer_indent_lines ( workspace_id , buf , start_line , finish_line , point_line , point_index )
617
590
__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!
877
850
end
878
851
879
852
def __spider_eval ( code , info = { } )
880
- id = @job_counter . next
881
-
882
- silent = info . fetch ( :silent , false )
883
-
884
853
# skip __nosave lines for error reporting
885
854
firstline = 1
886
855
firstline -= code . lines . to_a . take_while { |l | l . include? "#__nosave__" } . count
887
856
start_t_prom = Promise . new
888
857
info [ :workspace ] = 'eval' unless info [ :workspace ]
889
-
890
858
info [ :workspace ] . freeze
891
859
info . freeze
892
860
861
+ silent = info . fetch ( :silent , false )
862
+
893
863
job_in_thread = nil
864
+ id = @job_counter . next
865
+
894
866
job = Thread . new do
895
867
Thread . current . priority = 20
896
868
begin
897
- num_running_jobs = reg_job ( id , Thread . current )
869
+ num_running_jobs = register_job! ( id , Thread . current )
898
870
__system_thread_locals . set_local :sonic_pi_local_thread_group , "job-#{ id } "
899
871
__system_thread_locals . set_local :sonic_pi_spider_thread_id_path , ThreadId . new ( id )
900
872
__system_thread_locals . set_local :sonic_pi_spider_num_threads_spawned , 0
@@ -958,6 +930,7 @@ def __spider_eval(code, info={})
958
930
end
959
931
end
960
932
end
933
+
961
934
@user_jobs . add_job ( id , job , info )
962
935
963
936
Thread . new do
@@ -1245,7 +1218,7 @@ def __in_thread(*opts, &block)
1245
1218
1246
1219
private
1247
1220
1248
- def reg_job ( job_id , t )
1221
+ def register_job! ( job_id , t )
1249
1222
num_current_jobs = 0
1250
1223
@job_subthread_mutex . synchronize do
1251
1224
@job_subthreads [ job_id ] = Set . new
@@ -1406,60 +1379,33 @@ class Runtime
1406
1379
def initialize ( ports , msg_queue , user_methods )
1407
1380
1408
1381
@ports = ports
1382
+ @msg_queue = msg_queue
1383
+ @user_methods = user_methods
1384
+
1409
1385
@git_hash = __extract_git_hash
1410
1386
gh_short = @git_hash ? "-#{ @git_hash [ 0 , 5 ] } " : ""
1411
1387
@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
1414
1388
@version = Version . new ( 4 , 0 , 0 , "beta1" )
1415
1389
@server_version = __server_version
1416
1390
@life_hooks = LifeCycleHooks . new
1417
- @msg_queue = msg_queue
1418
1391
@cue_events = IncomingEvents . new
1419
1392
@job_counter = Counter . new ( -1 ) # Start counting jobs from 0
1420
1393
@job_subthreads = { }
1421
1394
@job_main_threads = { }
1422
1395
@named_subthreads = { }
1423
1396
@job_subthread_mutex = Mutex . new
1397
+ @osc_cue_server_mutex = Mutex . new
1424
1398
@user_jobs = Jobs . new
1425
- @user_methods = user_methods
1426
1399
@global_start_time = Time . now
1427
1400
@session_id = SecureRandom . uuid
1428
1401
@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
1458
1405
@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
1461
1406
@gui_cue_log_idxs = Counter . new
1462
- @osc_cue_server_mutex = Mutex . new
1407
+ @gui_heartbeats = { }
1408
+ @gui_last_heartbeat = nil
1463
1409
1464
1410
@register_cue_event_lambda = lambda do |t , p , i , d , b , m , address , args , sched_ahead_time = 0 |
1465
1411
t = t . to_r
@@ -1490,15 +1436,48 @@ def initialize(ports, msg_queue, user_methods)
1490
1436
end
1491
1437
end
1492
1438
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
+ } )
1494
1474
1495
- @gui_heartbeats = { }
1496
- @gui_last_heartbeat = nil
1497
1475
begin
1498
1476
@gitsave = GitSave . new ( Paths . project_path )
1499
1477
rescue
1500
1478
@gitsave = nil
1501
1479
end
1480
+
1502
1481
@save_queue = SizedQueue . new ( 20 )
1503
1482
1504
1483
@save_t = Thread . new do
@@ -1520,6 +1499,8 @@ def initialize(ports, msg_queue, user_methods)
1520
1499
end
1521
1500
end
1522
1501
1502
+ @system_state . set 0 , 0 , ThreadId . new ( -2 ) , 0 , 0 , 60 , :sched_ahead_time , default_sched_ahead_time
1503
+
1523
1504
__info "Welcome to Sonic Pi #{ version } " , 1
1524
1505
1525
1506
__info "Running on Ruby v#{ RUBY_VERSION } "
0 commit comments