synthdef 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ec5c7f7405fbd5da62bed4b75eb323c50e68561
4
- data.tar.gz: 513086de792c8c371b912a3e0fb00ffff0280840
3
+ metadata.gz: f9c8588c67ed85ad21a8d99a8137c050943f0c2d
4
+ data.tar.gz: 89e2c2d3bd2cabcafa5b18c02200cbb0d7705b61
5
5
  SHA512:
6
- metadata.gz: fabbd69d4e25c238f522f6eebb9ea075fda74f6ec3031779c802aee08f568f8151e47f52641523b7c53c27427efb241ca3a09e2de1bb26967202eaf0a16e73b9
7
- data.tar.gz: 3ff9d9c6a2f850b7084b00ee19dcb3eb188b37027c4259d540a24679789f046a6bd3d2c317b97f482742f6bf1864993d7eb0fc5a87ef52d009902d08db2e223f
6
+ metadata.gz: 6c8aa4387cb4868107d233ff0773df514603c7ac1019a894526bf2c116a08955c3af04393f6bc6bad0841ba52d076d7aa400bb0354097ad6cb78b69e4ceac93a
7
+ data.tar.gz: 1aa642d35abdef185c5dfc1a5499a03d6d40e3e82c55e62b64ce57d6abe1a7c252659329c525ddf1d1c1755ad388622c409786e0a90a3300e44f24c228081731
data/bin/synthdef CHANGED
@@ -1,5 +1,50 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'synthdef'
3
3
  require 'json'
4
+ require 'optparse'
4
5
 
5
- puts JSON.pretty_generate(Synthdef.read(ARGF.read).snapshot)
6
+ ARGV << '-h' if ARGV.empty?
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: synthdef [options] [path]"
11
+
12
+ opts.on("-c", "--convert [VERSION]", ["1", "2"], "Specify synthdef version of output") do |c|
13
+ options[:convert] = c
14
+ end
15
+
16
+ opts.on("-f", "--format [FORMAT]", ["json", "raw"], "Specify output format: json, raw") do |f|
17
+ options[:format] = f
18
+ end
19
+
20
+ # Another typical switch to print the version.
21
+ opts.on_tail("-v", "--version", "Show version") do
22
+ puts "synthdef gem version #{Synthdef::VERSION}"
23
+ puts "Manipulate SuperCollider synthdef files from the command line"
24
+ puts opts
25
+ exit
26
+ end
27
+ end.parse!
28
+
29
+ ## Work with STDIN and FILENAME and warn if not given
30
+ begin
31
+ if (ARGF.filename != "-" and File.exist?(File.expand_path(ARGF.filename))) or (not STDIN.tty? and not STDIN.closed?)
32
+ sdef = Synthdef.read(ARGF.read)
33
+ end
34
+ rescue Errno::ENOENT
35
+ $stderr.puts "Synthdef not found: #{ARGF.filename}"
36
+ exit 1
37
+ end
38
+
39
+ sdef[:file_version] = options[:convert].to_i if options[:convert]
40
+
41
+ options[:format] ||= "json"
42
+ case options[:format]
43
+ when "json"
44
+ puts JSON.pretty_generate(sdef.snapshot)
45
+ when "raw"
46
+ puts sdef.to_binary_s
47
+ else
48
+ $stderr.puts "Invalid output format chosen"
49
+ exit 1
50
+ end
data/lib/synthdef.rb CHANGED
@@ -24,35 +24,35 @@ class Synthdef < BinData::Record
24
24
  array :synthdefs, initial_length: lambda { no_of_synthdefs } do
25
25
  pascal_string :name
26
26
 
27
- choice :no_of_constants, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
27
+ choice :no_of_constants, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
28
28
  array :constants, initial_length: lambda { no_of_constants } do
29
29
  float :constant
30
30
  end
31
31
 
32
- choice :no_of_params, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
32
+ choice :no_of_params, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
33
33
  array :params, initial_length: lambda { no_of_params } do
34
34
  float :initial_parameter_value
35
35
  end
36
36
 
37
- choice :no_of_param_names, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
37
+ choice :no_of_param_names, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
38
38
  array :param_names, initial_length: lambda { no_of_param_names } do
39
39
  pascal_string :param_name
40
- choice :param_index, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
40
+ choice :param_index, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
41
41
  end
42
42
 
43
- choice :no_of_ugens, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
43
+ choice :no_of_ugens, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
44
44
  array :ugens, initial_length: lambda { no_of_ugens } do
45
45
  pascal_string :ugen_name
46
46
  int8 :rate
47
- choice :no_of_inputs, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
48
- choice :no_of_outputs, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
47
+ choice :no_of_inputs, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
48
+ choice :no_of_outputs, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
49
49
  int16 :special, initial_value: 0
50
50
  array :inputs, initial_length: lambda { no_of_inputs } do
51
- choice :src, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
51
+ choice :src, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
52
52
  if lambda { src == -1 }
53
- choice :input_constant_index, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
53
+ choice :input_constant_index, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
54
54
  else
55
- choice :input_ugen_index, :selection => :check_version, :choices => {0 => :int16, 1 => :int32}
55
+ choice :input_ugen_index, :selection => :check_version, :copy_on_change => true, :choices => {0 => :int16, 1 => :int32}
56
56
  end
57
57
  end
58
58
  array :outputs, initial_length: lambda { no_of_outputs } do
@@ -1,5 +1,5 @@
1
1
  require 'bindata'
2
2
 
3
3
  class Synthdef < BinData::Record
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'active_support'
2
3
 
3
4
  describe Synthdef do
4
5
  let(:synthdef_binary) { IO.read(File.expand_path("../data/recorder.scsyndef", __FILE__)) }
@@ -27,4 +28,15 @@ describe Synthdef do
27
28
  expect(parsed_synthdef[:synthdefs].first[:ugens].last[:ugen_name]).to eq("Out")
28
29
  expect(parsed_synthdef[:synthdefs].first[:no_of_variants]).to eq(0)
29
30
  end
31
+
32
+ it 'converts a basic version 1 synthdef to a version 2 synthdef' do
33
+ parsed_synthdef = Synthdef.read(synthdef_binary)
34
+ parsed_synthdef[:file_version] = 2
35
+
36
+ converted_synthdef = Synthdef.read(parsed_synthdef.to_binary_s).snapshot
37
+ expect(converted_synthdef).to be_a(Hash)
38
+ expect(converted_synthdef).not_to be_empty
39
+ expect(converted_synthdef[:file_version]).to eq(2)
40
+ expect(converted_synthdef.to_h.except(:file_version)).to eq(parsed_synthdef.snapshot.to_h.except(:file_version))
41
+ end
30
42
  end
data/synthdef.gemspec CHANGED
@@ -23,9 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "guard"
27
- spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "activesupport"
27
+ # spec.add_development_dependency "guard"
28
+ # spec.add_development_dependency "guard-rspec"
28
29
  spec.add_development_dependency "pry"
29
- spec.add_development_dependency "pry-remote"
30
- spec.add_development_dependency "pry-nav"
30
+ # spec.add_development_dependency "pry-remote"
31
+ # spec.add_development_dependency "pry-nav"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synthdef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -67,21 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: guard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: guard-rspec
70
+ name: activesupport
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -108,34 +94,6 @@ dependencies:
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: pry-remote
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: pry-nav
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
97
  description: Use the power of Ruby to convert, edit and save synthdefs for SuperCollider
140
98
  email:
141
99
  - xavriley@hotmail.com
@@ -189,4 +147,3 @@ test_files:
189
147
  - spec/data/stereo_player.scsyndef
190
148
  - spec/spec_helper.rb
191
149
  - spec/synthdef_spec.rb
192
- has_rdoc: