sonic-pi-cli 0.0.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/sonic_pi +6 -4
- data/lib/sonic_pi.rb +35 -12
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69fb6262128d0b144aeb03a3135b5fa19eeed8d52a3fefab4f5c6317356983cc
|
4
|
+
data.tar.gz: e3c6d4c4ccc9cb99675dd537d7f08ae5d9b00c0b31639ea4ffba1f2cf28cb17c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99d188d6b33023baf1cab49f51615b203f3dd0b0c6c436a4893027baf2e7a95aa5b602481e7b74c58e16e65c51b657172c38ae16bd8c76f31e232fbebef42a0b
|
7
|
+
data.tar.gz: 77010bf05ef77eec503f9eb0c31a4acbed999cfc25bce50e63968031a708c220e96e6c8ffc97acb77ecef75f3715ce7c69e8ead752361b8e7c95a7c8ecd0119d
|
data/bin/sonic_pi
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "sonic_pi"
|
4
4
|
|
5
5
|
def stdin
|
6
6
|
unless STDIN.tty?
|
@@ -45,14 +45,16 @@ end
|
|
45
45
|
def run
|
46
46
|
app = SonicPi.new
|
47
47
|
|
48
|
-
app.test_connection!
|
49
|
-
|
50
48
|
case args_and_stdin
|
51
|
-
when '--help', ''
|
49
|
+
when '--help', '-h', ''
|
52
50
|
print_help
|
53
51
|
when 'stop'
|
52
|
+
app.test_connection!
|
53
|
+
|
54
54
|
app.stop
|
55
55
|
else
|
56
|
+
app.test_connection!
|
57
|
+
|
56
58
|
app.run(args_and_stdin)
|
57
59
|
end
|
58
60
|
end
|
data/lib/sonic_pi.rb
CHANGED
@@ -4,25 +4,30 @@ require 'osc-ruby'
|
|
4
4
|
require 'securerandom'
|
5
5
|
|
6
6
|
class SonicPi
|
7
|
+
PORT_LOG_REGEX = Regexp.compile(/Listen port:\s+(?<port>\d+)/)
|
8
|
+
|
9
|
+
def initialize(port=nil)
|
10
|
+
@port = port || find_port
|
11
|
+
end
|
12
|
+
|
7
13
|
RUN_COMMAND = "/run-code"
|
8
14
|
STOP_COMMAND = "/stop-all-jobs"
|
9
15
|
SERVER = 'localhost'
|
10
|
-
PORT = 4557
|
11
16
|
GUI_ID = 'SONIC_PI_CLI'
|
12
17
|
|
13
18
|
def run(command)
|
14
|
-
|
19
|
+
send_command(RUN_COMMAND, command)
|
15
20
|
end
|
16
21
|
|
17
22
|
def stop
|
18
|
-
|
23
|
+
send_command(STOP_COMMAND)
|
19
24
|
end
|
20
25
|
|
21
26
|
def test_connection!
|
22
27
|
begin
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
socket = UDPSocket.new
|
29
|
+
socket.bind(nil, @port)
|
30
|
+
abort("ERROR: Sonic Pi is not listening on #{@port} - is it running?")
|
26
31
|
rescue
|
27
32
|
# everything is good
|
28
33
|
end
|
@@ -31,15 +36,33 @@ class SonicPi
|
|
31
36
|
private
|
32
37
|
|
33
38
|
def client
|
34
|
-
client ||= OSC::Client.new(SERVER,
|
39
|
+
@client ||= OSC::Client.new(SERVER, @port)
|
35
40
|
end
|
36
41
|
|
37
|
-
def
|
38
|
-
OSC::Message.new(
|
42
|
+
def send_command(call_type, command=nil)
|
43
|
+
prepared_command = OSC::Message.new(call_type, GUI_ID, command)
|
44
|
+
client.send(prepared_command)
|
39
45
|
end
|
40
46
|
|
41
|
-
def
|
42
|
-
|
47
|
+
def find_port
|
48
|
+
port = 4557
|
49
|
+
|
50
|
+
begin
|
51
|
+
log_path = File.join(Dir.home, ".sonic-pi", "log", "server-output.log")
|
52
|
+
|
53
|
+
File.open(log_path, 'r') do |f|
|
54
|
+
port_log_entry =
|
55
|
+
f.each_line
|
56
|
+
.lazy
|
57
|
+
.map { |line| line[PORT_LOG_REGEX, "port"] }
|
58
|
+
.find { |match| !!match }
|
59
|
+
|
60
|
+
port = port_log_entry.to_i if port_log_entry
|
61
|
+
end
|
62
|
+
rescue Errno::ENOENT
|
63
|
+
# not to worry if the file doesn't exist
|
64
|
+
end
|
65
|
+
|
66
|
+
port
|
43
67
|
end
|
44
68
|
end
|
45
|
-
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sonic-pi-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Johnstone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: osc-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1'
|
27
27
|
description: A simple command line interface for Sonic Pi
|
28
28
|
email: ncwjohnstone@gmail.com
|
29
29
|
executables:
|
@@ -52,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
|
56
|
-
rubygems_version: 2.2.2
|
55
|
+
rubygems_version: 3.0.3
|
57
56
|
signing_key:
|
58
57
|
specification_version: 4
|
59
58
|
summary: Sonic Pi CLI
|