spx 0.1.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +12 -0
- data/exe/spx +7 -0
- data/lib/spx/cli.rb +62 -0
- data/lib/spx/log_parser.rb +23 -0
- data/lib/spx/runner.rb +113 -0
- data/lib/spx/version.rb +5 -0
- data/lib/spx.rb +11 -0
- data/sig/spx.rbs +4 -0
- data/tmp/.keep +0 -0
- metadata +99 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d5aabd4bf42589db840b334c70bcd52eab1b804c158d5033cec5380b0aff4ffe
|
|
4
|
+
data.tar.gz: 8fa38529f785f379e882e0f3da6718d1cc5aeef6b35eb770d0ccc019aebfbcee
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 93b28fa5b6a9ef1c080082715f14b363edd5aad05800951259745052ca283d2fdd1317b6416408cdf5f12a73589db716faadd4a3a055e0343385050270ab0fbc
|
|
7
|
+
data.tar.gz: 8636c6a04e79fdb206accd802a4991c43d1a317ea34ea02ffd1fb72c00116681b85fdd7cb1953a3127c82e582f5829985f0d31c962e9f2e11dd1ea02ccdb8549
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.1
|
|
3
|
+
Exclude:
|
|
4
|
+
- spec/fixtures/*
|
|
5
|
+
|
|
6
|
+
Metrics/BlockLength:
|
|
7
|
+
Exclude:
|
|
8
|
+
- spec/**/*
|
|
9
|
+
|
|
10
|
+
Style/Documentation:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
Style/StringLiterals:
|
|
14
|
+
EnforcedStyle: double_quotes
|
|
15
|
+
|
|
16
|
+
Style/StringLiteralsInInterpolation:
|
|
17
|
+
EnforcedStyle: double_quotes
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 tnantoka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Spx: Sonic Pi eXecutor
|
|
2
|
+
|
|
3
|
+
Spx is a CLI tool to play or record Sonic Pi code by using Sonic Pi's built-in OSC server.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- [Sonic Pi](https://github.com/sonic-pi-net/sonic-pi) (version 4.5.0 or later)
|
|
8
|
+
- Ruby
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Help
|
|
14
|
+
gem exec spx
|
|
15
|
+
|
|
16
|
+
# Test connection to Sonic Pi
|
|
17
|
+
gem exec spx test_connection
|
|
18
|
+
|
|
19
|
+
# Play Sonic Pi code
|
|
20
|
+
gem exec spx play path/to/sonic-pi-code.rb
|
|
21
|
+
|
|
22
|
+
# Record Sonic Pi code
|
|
23
|
+
gem exec spx record path/to/sonic-pi-code.rb -o path/to/output.wav
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If `gem exec` is not available, you can use the following command instead:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install -g spx
|
|
30
|
+
spx
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
36
|
+
|
|
37
|
+
## Acknowledgements
|
|
38
|
+
|
|
39
|
+
- https://github.com/sonic-pi-net/sonic-pi
|
|
40
|
+
- https://rubygems.org/gems/sonic-pi-cli4
|
data/Rakefile
ADDED
data/exe/spx
ADDED
data/lib/spx/cli.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spx
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
class << self
|
|
6
|
+
def shared_options
|
|
7
|
+
method_option :sonic_pi_log, aliases: "-l", desc: "Log file to parse port number and token",
|
|
8
|
+
default: "~/.sonic-pi/log/spider.log"
|
|
9
|
+
method_option :callback_port, aliases: "-p", desc: "UDP port to receive messages from Sonic Pi", default: "3333"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
desc "test-connection", "Test connection to Sonic Pi"
|
|
14
|
+
shared_options
|
|
15
|
+
def test_connection
|
|
16
|
+
runner.test_connection.tap do |connected|
|
|
17
|
+
say connected ? "OK" : "NG"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc "play SOURCE", "Play a Sonic Pi file"
|
|
22
|
+
shared_options
|
|
23
|
+
def play(file)
|
|
24
|
+
unless runner.test_connection
|
|
25
|
+
say "Cannot connect to Sonic Pi"
|
|
26
|
+
return false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
runner.play(File.read(file))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
desc "record SOURCE", "Record a Sonic Pi session to a file"
|
|
33
|
+
shared_options
|
|
34
|
+
method_option :output, aliases: "-o", desc: "Output file", default: "./output.wav"
|
|
35
|
+
def record(file)
|
|
36
|
+
unless runner.test_connection
|
|
37
|
+
say "Cannot connect to Sonic Pi"
|
|
38
|
+
return false
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
runner.record(
|
|
42
|
+
File.read(file),
|
|
43
|
+
File.expand_path(options[:output])
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
desc "version", "Show version"
|
|
48
|
+
def version
|
|
49
|
+
say Spx::VERSION
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def runner
|
|
55
|
+
@runner ||= begin
|
|
56
|
+
parser = LogParser.new(File.expand_path(options[:sonic_pi_log]))
|
|
57
|
+
port, token = parser.parse.values_at(:port, :token)
|
|
58
|
+
Runner.new(port, token, options[:callback_port].to_i)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spx
|
|
4
|
+
class LogParser
|
|
5
|
+
def initialize(log_file_path)
|
|
6
|
+
@log_file_path = log_file_path
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def parse
|
|
10
|
+
port = nil
|
|
11
|
+
token = nil
|
|
12
|
+
|
|
13
|
+
File.foreach(@log_file_path) do |line|
|
|
14
|
+
token ||= line[/Token:\s+(-?\d+)/, 1]&.to_i
|
|
15
|
+
port ||= line[/:server_port=>(\d+)/, 1]&.to_i
|
|
16
|
+
|
|
17
|
+
break if port && token
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
{ port: port, token: token }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/spx/runner.rb
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spx
|
|
4
|
+
class Runner
|
|
5
|
+
HOST = "localhost"
|
|
6
|
+
MESSAGES = {
|
|
7
|
+
run_code: "/run-code",
|
|
8
|
+
start_recording: "/start-recording",
|
|
9
|
+
stop_recording: "/stop-recording",
|
|
10
|
+
save_recording: "/save-recording",
|
|
11
|
+
test_callback: "/test-callback",
|
|
12
|
+
record_callback: "/record-callback"
|
|
13
|
+
}.freeze
|
|
14
|
+
TIMES = {
|
|
15
|
+
test_timeout: 1,
|
|
16
|
+
stop_margin: 1
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
def initialize(port, token, callback_port)
|
|
20
|
+
@port = port
|
|
21
|
+
@token = token
|
|
22
|
+
@callback_port = callback_port
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_connection # rubocop:disable Metrics/MethodLength
|
|
26
|
+
connected = false
|
|
27
|
+
|
|
28
|
+
run_with_callback("", MESSAGES[:test_callback]) do
|
|
29
|
+
connected = true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Timeout.timeout(TIMES[:test_timeout]) do
|
|
33
|
+
loop do
|
|
34
|
+
sleep 0.1
|
|
35
|
+
break if connected
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
true
|
|
40
|
+
rescue Timeout::Error
|
|
41
|
+
false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def play(code)
|
|
45
|
+
send_message(MESSAGES[:run_code], code)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def record(code, output_file) # rubocop:disable Metrics/MethodLength
|
|
49
|
+
start_recording
|
|
50
|
+
|
|
51
|
+
recorded = false
|
|
52
|
+
|
|
53
|
+
run_with_callback(code, MESSAGES[:record_callback]) do
|
|
54
|
+
sleep TIMES[:stop_margin]
|
|
55
|
+
stop_recording
|
|
56
|
+
save_recording(output_file)
|
|
57
|
+
recorded = true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
loop do
|
|
61
|
+
sleep 0.1
|
|
62
|
+
break if recorded
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def start_recording
|
|
69
|
+
send_message(MESSAGES[:start_recording])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def stop_recording
|
|
73
|
+
send_message(MESSAGES[:stop_recording])
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def save_recording(file_path)
|
|
77
|
+
send_message(MESSAGES[:save_recording], file_path)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def send_message(type, body = nil)
|
|
81
|
+
prepared = OSC::Message.new(type, @token, body)
|
|
82
|
+
client.send(prepared)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def client
|
|
86
|
+
@client ||= OSC::Client.new(HOST, @port)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def code_with_callback(code, type)
|
|
90
|
+
[
|
|
91
|
+
code,
|
|
92
|
+
"osc_send 'localhost', 3333, '#{type}'"
|
|
93
|
+
].join("\n")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def run_with_callback(code, type, &callback)
|
|
97
|
+
server.add_method(type.dup) do
|
|
98
|
+
callback.call
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
send_message(
|
|
102
|
+
MESSAGES[:run_code],
|
|
103
|
+
code_with_callback(code, type)
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def server
|
|
108
|
+
@server ||= OSC::Server.new(@callback_port).tap do |server|
|
|
109
|
+
Thread.new { server.run }
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
data/lib/spx/version.rb
ADDED
data/lib/spx.rb
ADDED
data/sig/spx.rbs
ADDED
data/tmp/.keep
ADDED
|
File without changes
|
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: spx
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tnantoka
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: osc-ruby
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: ostruct
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.6.3
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.6.3
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: thor
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.4'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.4'
|
|
54
|
+
description: A CLI tool to play or record Sonic Pi code by using Sonic Pi's built-in
|
|
55
|
+
OSC server.
|
|
56
|
+
email:
|
|
57
|
+
- tnantoka@bornneet.com
|
|
58
|
+
executables:
|
|
59
|
+
- spx
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- ".rubocop.yml"
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- exe/spx
|
|
69
|
+
- lib/spx.rb
|
|
70
|
+
- lib/spx/cli.rb
|
|
71
|
+
- lib/spx/log_parser.rb
|
|
72
|
+
- lib/spx/runner.rb
|
|
73
|
+
- lib/spx/version.rb
|
|
74
|
+
- sig/spx.rbs
|
|
75
|
+
- tmp/.keep
|
|
76
|
+
homepage: https://github.com/tnantoka/spx
|
|
77
|
+
licenses:
|
|
78
|
+
- MIT
|
|
79
|
+
metadata:
|
|
80
|
+
homepage_uri: https://github.com/tnantoka/spx
|
|
81
|
+
source_code_uri: https://github.com/tnantoka/spx
|
|
82
|
+
rdoc_options: []
|
|
83
|
+
require_paths:
|
|
84
|
+
- lib
|
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 3.1.0
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
requirements: []
|
|
96
|
+
rubygems_version: 3.6.9
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: Sonic Pi eXecutor
|
|
99
|
+
test_files: []
|