sonic-pi-cli 0.1.3 → 0.2.0

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 +4 -4
  2. data/bin/sonic_pi +1 -25
  3. data/lib/sonic_pi.rb +26 -2
  4. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56c7ffafe6adcba49b7448fbf712920476cb7c1cec31a0e117b4fa9b466c015c
4
- data.tar.gz: aaef39b5888f51b5889d6860b5759c2118668f600bff6c2ed23598482198b060
3
+ metadata.gz: 69fb6262128d0b144aeb03a3135b5fa19eeed8d52a3fefab4f5c6317356983cc
4
+ data.tar.gz: e3c6d4c4ccc9cb99675dd537d7f08ae5d9b00c0b31639ea4ffba1f2cf28cb17c
5
5
  SHA512:
6
- metadata.gz: f27cf2472303f9fd0458370da7947aa812ac2e150bd2db7b618286baf750b65d014eb6a749fe16ea1eb95da5a13eb1114ace445ee64177a8f7713f98bed018db
7
- data.tar.gz: 49877b80ce03c869ccbf126c72f65e043d011b9b1e81461750bbb853b7aed10d1496b1c9d7cb30a9ee0d370e6519a0b1af1c12f74f4b335885fe3268043e0d51
6
+ metadata.gz: 99d188d6b33023baf1cab49f51615b203f3dd0b0c6c436a4893027baf2e7a95aa5b602481e7b74c58e16e65c51b657172c38ae16bd8c76f31e232fbebef42a0b
7
+ data.tar.gz: 77010bf05ef77eec503f9eb0c31a4acbed999cfc25bce50e63968031a708c220e96e6c8ffc97acb77ecef75f3715ce7c69e8ead752361b8e7c95a7c8ecd0119d
@@ -2,36 +2,12 @@
2
2
 
3
3
  require "sonic_pi"
4
4
 
5
- PORT_LOG_REGEX = Regexp.compile(/Listen port:\s+(?<port>\d+)/)
6
-
7
5
  def stdin
8
6
  unless STDIN.tty?
9
7
  $stdin.read
10
8
  end
11
9
  end
12
10
 
13
- def find_port
14
- port = 4557
15
-
16
- begin
17
- log_path = File.join(Dir.home, ".sonic-pi", "log", "server-output.log")
18
-
19
- File.open(log_path, 'r') do |f|
20
- port_log_entry =
21
- f.each_line
22
- .lazy
23
- .map { |line| line[PORT_LOG_REGEX, "port"] }
24
- .find { |match| !!match }
25
-
26
- port = port_log_entry.to_i if port_log_entry
27
- end
28
- rescue Errno::ENOENT
29
- # not to worry if the file doesn't exist
30
- end
31
-
32
- port
33
- end
34
-
35
11
  def args
36
12
  ARGV.join(' ')
37
13
  end
@@ -67,7 +43,7 @@ HELP
67
43
  end
68
44
 
69
45
  def run
70
- app = SonicPi.new(find_port)
46
+ app = SonicPi.new
71
47
 
72
48
  case args_and_stdin
73
49
  when '--help', '-h', ''
@@ -4,8 +4,10 @@ require 'osc-ruby'
4
4
  require 'securerandom'
5
5
 
6
6
  class SonicPi
7
- def initialize(port=4557)
8
- @port=port
7
+ PORT_LOG_REGEX = Regexp.compile(/Listen port:\s+(?<port>\d+)/)
8
+
9
+ def initialize(port=nil)
10
+ @port = port || find_port
9
11
  end
10
12
 
11
13
  RUN_COMMAND = "/run-code"
@@ -41,4 +43,26 @@ class SonicPi
41
43
  prepared_command = OSC::Message.new(call_type, GUI_ID, command)
42
44
  client.send(prepared_command)
43
45
  end
46
+
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
67
+ end
44
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonic-pi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Johnstone
@@ -14,16 +14,16 @@ dependencies:
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: '0'
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: '0'
26
+ version: '1'
27
27
  description: A simple command line interface for Sonic Pi
28
28
  email: ncwjohnstone@gmail.com
29
29
  executables: