sonic-pi-cli4 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/sonic_pi4 +103 -0
  3. data/lib/sonic_piRBN.rb +49 -0
  4. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8c7da055b4b9e1e699859b68738a50401c727f2bc49b06440c841d4fc50dd9a2
4
+ data.tar.gz: 640a512f4652e1d4c7ec94401e8466c4998da80590a36a4cb04a0ccf00eb9e59
5
+ SHA512:
6
+ metadata.gz: b3005ddaf3adf0beb0d5b1a42fe622de4776c7d74c4ee0c20c2ac638e11028cdd4d3b259926e9f6bead14e233409828e1875f066d87f6918318feda3d2cc5983
7
+ data.tar.gz: 28016e49f00e33e9f3599ad748066c8fc021038ecfff6f8b658c70348a7736b1abbcf8503cb51733aeb3953c29cf3cc98c096dc6b2026d9965ab8a55a0d27dd1
data/bin/sonic_pi4 ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sonic_piRBN'
4
+
5
+ def stdin
6
+ unless STDIN.tty?
7
+ $stdin.read
8
+ end
9
+ end
10
+
11
+ def token #this functions reads from the spider-log
12
+ #the dynamically allocated token value used in internal gui comms
13
+ value='' #initialise variable
14
+ #read spider.log
15
+ File.open(ENV['HOME']+'/.sonic-pi/log/spider.log','r') do |f1|
16
+ while l = f1.gets
17
+ if l.include?"Token:" #find line containing Listen port:
18
+ value = l.split(" ").last.to_i #extract token value
19
+ break
20
+ end
21
+ end
22
+ f1.close #close file
23
+ end
24
+ return value #return found port value
25
+ end
26
+
27
+ def pvalue
28
+ value='' #initialise variable
29
+ #read spider.log
30
+ File.open(ENV['HOME']+'/.sonic-pi/log/spider.log','r') do |f1|
31
+ while l = f1.gets
32
+ if l.include?"Ports:"
33
+ #k="Ports: {:server_port=>37153, :gui_port=>37154, :scsynth_port=>37155, :scsynth_send_port=>37155, :osc_cues_port=>4560, :tau_port=>37156, :listen_to_tau_port=>37160}"
34
+ v=l.split("{")[1]
35
+ pp=v.split(", ")
36
+ pp.each.with_index do |i|
37
+ if i.include? ":server_port"
38
+ value= i.split("=>")[1].to_i
39
+ end
40
+ end
41
+ break
42
+ end
43
+ end
44
+ f1.close#close file
45
+ end
46
+ return value #return found port value
47
+ end
48
+
49
+
50
+
51
+ def args
52
+ ARGV.join(' ')
53
+ end
54
+
55
+ def args_and_stdin
56
+ @args_and_stdin ||= [
57
+ args,
58
+ stdin,
59
+ ].join("\n").strip
60
+ end
61
+
62
+ def print_help
63
+ puts <<-HELP
64
+ sonic-pi-cli4
65
+
66
+ Usage:
67
+ sonic_pi4 <code>
68
+ sonic_pi4 stop
69
+ cat music.rb | sonic_pi4
70
+ sonic_pi4 --help
71
+
72
+ Sonic Pi version 4 must be running for this utility to work.
73
+ You can pipe code to stdin to execute it.
74
+
75
+ Options:
76
+ <code> Run the given code.
77
+ stop Stop all running music.
78
+ --help Display this text.
79
+
80
+ Modified by Robin Newman for Sonic Pi v4
81
+ Original version made by Nick Johnstone (github.com/Widdershin/sonic-pi-cli).
82
+ Thanks to Sam Aaron for creating Sonic Pi.
83
+ HELP
84
+ end
85
+
86
+ def run
87
+ app = SonicPiRBN.new(pvalue,token) #pass in port value
88
+
89
+ case args_and_stdin
90
+ when '--help', '-h', ''
91
+ print_help
92
+ when 'stop'
93
+ app.test_connection!
94
+
95
+ app.stop
96
+ else
97
+ app.test_connection!
98
+
99
+ app.run(args_and_stdin)
100
+ end
101
+ end
102
+
103
+ run
@@ -0,0 +1,49 @@
1
+ require 'socket'
2
+ require 'rubygems'
3
+ require 'osc-ruby'
4
+ require 'securerandom'
5
+
6
+ class SonicPiRBN
7
+
8
+ def initialize(port='',token='')
9
+ @port=port
10
+ @token = token
11
+ end
12
+
13
+ RUN_COMMAND = "/run-code"
14
+ STOP_COMMAND = "/stop-all-jobs"
15
+ SERVER = 'localhost'
16
+
17
+
18
+
19
+ def run(command)
20
+
21
+ send_command(RUN_COMMAND, command)
22
+ end
23
+
24
+ def stop
25
+ send_command(STOP_COMMAND)
26
+ end
27
+
28
+ def test_connection!
29
+ begin
30
+ socket = UDPSocket.new
31
+ socket.bind(nil, @port)
32
+ abort("ERROR: Sonic Pi is not listening on #{@port} - is it running?")
33
+ rescue
34
+ # everything is good
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def client
41
+ @client ||= OSC::Client.new(SERVER, @port)
42
+ end
43
+
44
+ def send_command(call_type, command=nil)
45
+ prepared_command = OSC::Message.new(call_type, @token, command)
46
+ #STDOUT.puts call_type,@token,command #for debugging
47
+ client.send(prepared_command)
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sonic-pi-cli4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Robin Newman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: osc-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ description: A simple command line interface for Sonic Pi
28
+ email: robin.newman@gmail.com
29
+ executables:
30
+ - sonic_pi4
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - bin/sonic_pi4
35
+ - lib/sonic_piRBN.rb
36
+ homepage: http://rubygems.org/gems/sonic-pi-cli4
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.3.7
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Sonic Pi CLI for v4
59
+ test_files: []