maxy-gen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6544b65a84167acfcb482cfe7f86524bafd8cd3c
4
+ data.tar.gz: 37c1356e292db87822fa7f51361c2b13b3e5c0f8
5
+ SHA512:
6
+ metadata.gz: c543c5183934c2fc99105118515a60340b8b0695889ddbbcfacf20363ea234f1e7ed724fd4a23ef16e90379c673fbe1f3d61ff08d4ca0d88f52c5c8c9151fb8a
7
+ data.tar.gz: 57e90872d4b36183206526d12b480d9a876177ffe7e53fdb6a5002a3163d8626364fefd77c29873c319f1acb3ccb95d29e6eca67aaf90af199dd2d909104793f
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .idea/**
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in maxy-gen.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ maxy-gen (0.1.0)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aruba (0.14.5)
11
+ childprocess (>= 0.6.3, < 0.10.0)
12
+ contracts (~> 0.9)
13
+ cucumber (>= 1.3.19)
14
+ ffi (~> 1.9.10)
15
+ rspec-expectations (>= 2.99)
16
+ thor (~> 0.19)
17
+ backports (3.11.3)
18
+ builder (3.2.3)
19
+ childprocess (0.9.0)
20
+ ffi (~> 1.0, >= 1.0.11)
21
+ contracts (0.16.0)
22
+ cucumber (3.1.0)
23
+ builder (>= 2.1.2)
24
+ cucumber-core (~> 3.1.0)
25
+ cucumber-expressions (~> 5.0.4)
26
+ cucumber-wire (~> 0.0.1)
27
+ diff-lcs (~> 1.3)
28
+ gherkin (~> 5.0)
29
+ multi_json (>= 1.7.5, < 2.0)
30
+ multi_test (>= 0.1.2)
31
+ cucumber-core (3.1.0)
32
+ backports (>= 3.8.0)
33
+ cucumber-tag_expressions (~> 1.1.0)
34
+ gherkin (>= 5.0.0)
35
+ cucumber-expressions (5.0.18)
36
+ cucumber-tag_expressions (1.1.1)
37
+ cucumber-wire (0.0.1)
38
+ diff-lcs (1.3)
39
+ ffi (1.9.23)
40
+ gherkin (5.1.0)
41
+ multi_json (1.13.1)
42
+ multi_test (0.1.2)
43
+ rake (10.5.0)
44
+ rspec (3.7.0)
45
+ rspec-core (~> 3.7.0)
46
+ rspec-expectations (~> 3.7.0)
47
+ rspec-mocks (~> 3.7.0)
48
+ rspec-core (3.7.1)
49
+ rspec-support (~> 3.7.0)
50
+ rspec-expectations (3.7.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.7.0)
53
+ rspec-mocks (3.7.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.7.0)
56
+ rspec-support (3.7.1)
57
+ thor (0.20.0)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ aruba
64
+ bundler (~> 1.14)
65
+ cucumber
66
+ maxy-gen!
67
+ rake (~> 10.0)
68
+ rspec (~> 3.0)
69
+
70
+ BUNDLED WITH
71
+ 1.14.6
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Maxy::Gen
2
+
3
+ A commandline tool to generate max patches in an emmet-like fashion
4
+
5
+ ## Installation
6
+
7
+ Requires `ruby` installed, of course. This gem was built with v.2.3.3.
8
+
9
+ Install the gem:
10
+
11
+ $ gem install maxy-gen
12
+
13
+ ## Usage
14
+
15
+ Use an [emmet](https://emmet.io/)-like pattern to generate a max patch, e.g.
16
+
17
+ $ maxy-gen generate 'cycle~{440.}-*~{0.2}-ezdac~' > test.maxpat
18
+
19
+
20
+ ... and open it in Max.
21
+
22
+ As of now you can use
23
+
24
+ - `-` dashes to indicate patch chords
25
+ - `{}` curly braces to denote arguments passed to objects
26
+
27
+ This gem is under heavy development and needs a library of max objects to function.
28
+
29
+ This early prototype supports
30
+ - `cycle~`
31
+ - `ezdac~`
32
+ - `sig~`
33
+ - `*~`
34
+
35
+ - (later, you will be able to use escaped identifiers, such as `\-~`, because `-{}` are taken, obviously )
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/julianrubisch/maxy-gen.
40
+
41
+ Please include:
42
+ - a description of what didn't work
43
+ - the patch produced by maxy-gen
44
+ - the patch as you'd have expected it
45
+
46
+ ## Support
47
+ This is a pure side project and depends on your support!
48
+
49
+ If you'd like to support the development of `maxy-gen` and my other projects, take a look at [https://www.patreon.com/znibbles](https://www.patreon.com/znibbles)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/assets/blank.yml ADDED
@@ -0,0 +1,42 @@
1
+ patcher:
2
+ fileversion: 1,
3
+ appversion:
4
+ major: 7
5
+ minor: 3
6
+ revision: 4
7
+ architecture: "x86"
8
+ modernui: 1
9
+ rect: [ 20.0, 20.0, 640.0, 480.0 ]
10
+ bglocked: 0
11
+ openinpresentation: 0
12
+ default_fontsize: 12.0
13
+ default_fontface: 0
14
+ default_fontname: "Arial"
15
+ gridonopen: 1
16
+ gridsize: [ 15.0, 15.0 ]
17
+ gridsnaponopen: 1
18
+ objectsnaponopen: 1
19
+ statusbarvisible: 2
20
+ toolbarvisible: 1
21
+ lefttoolbarpinned: 0
22
+ toptoolbarpinned: 0
23
+ righttoolbarpinned: 0
24
+ bottomtoolbarpinned: 0
25
+ toolbars_unpinned_last_save: 0
26
+ tallnewobj: 0
27
+ boxanimatetime: 200
28
+ enablehscroll: 1
29
+ enablevscroll: 1
30
+ devicewidth: 0.0
31
+ description: ""
32
+ digest: ""
33
+ tags: ""
34
+ style: ""
35
+ subpatcher_template: ""
36
+ boxes:
37
+ -
38
+ lines:
39
+ -
40
+ dependency_cache:
41
+ -
42
+ autosave: 0
@@ -0,0 +1,32 @@
1
+ objects:
2
+ 'cycle~':
3
+ maxclass: "newobj"
4
+ numinlets: 2
5
+ numoutlets: 1
6
+ outlettype:
7
+ - "signal"
8
+ style: ""
9
+ text: "cycle~"
10
+ 'ezdac~':
11
+ maxclass: 'ezdac~'
12
+ numinlets: 2
13
+ numoutlets: 0
14
+ width: 45
15
+ height: 45
16
+ style: ''
17
+ 'sig~':
18
+ maxclass: 'newobj'
19
+ numinlets: 1
20
+ numoutlets: 1
21
+ outlettype:
22
+ - "signal"
23
+ style: ""
24
+ text: "sig~"
25
+ '*~':
26
+ maxclass: 'newobj'
27
+ numinlets: 2
28
+ numoutlets: 1
29
+ outlettype:
30
+ - "signal"
31
+ style: ""
32
+ text: "*~"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "maxy/gen"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/maxy-gen ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'maxy/gen/cli'
3
+ Maxy::Gen::CLI.start
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+ require 'psych'
3
+ require 'json'
4
+ require 'maxy/gen'
5
+
6
+ module Maxy
7
+ module Gen
8
+ class CLI < Thor
9
+ desc "generate PATTERN", "Generates a Max Patch JSON from an emmet-style pattern"
10
+ method_option :blank, aliases: "-b"
11
+ def generate(pattern='')
12
+ puts Generator.new.generate(nil) and return if options[:blank]
13
+
14
+ tokens = Tokenizer.new(pattern).tokenize
15
+ tree = Parser.new(tokens).parse
16
+
17
+ puts Generator.new.generate(tree)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require 'psych'
3
+
4
+ module Maxy
5
+ module Gen
6
+ class Generator
7
+ TEMPLATE = Psych.load_file(File.join(__dir__, '../../../assets/blank.yml')).freeze
8
+ LIBRARY = Psych.load_file(File.join(__dir__, '../../../assets/library.yml')).freeze
9
+ OFFSET_X = 20
10
+ OFFSET_Y = 20
11
+ STEP_Y = 40
12
+ HEIGHT = 22
13
+ WIDTH = 50
14
+
15
+ def initialize
16
+ @object_count = 1
17
+ @patch = TEMPLATE.freeze
18
+ end
19
+
20
+ def generate(node)
21
+ return JSON.generate(@patch) if node.nil?
22
+
23
+ generate_node(node, "obj_#{@object_count}")
24
+ JSON.generate(@patch)
25
+ end
26
+
27
+ def generate_node(node, id)
28
+ @patch['patcher']['boxes'] << make_box(node, id)
29
+ @object_count += 1
30
+
31
+ node.child_nodes.each do |child_node|
32
+ child_id = "obj_#{@object_count}"
33
+ generate_node(child_node, child_id)
34
+ @patch['patcher']['lines'] << make_line(id, child_id)
35
+ end
36
+ end
37
+
38
+ def make_box(node, id)
39
+ box = LIBRARY['objects'][node.name]
40
+ box['id'] = id
41
+ box['patching_rect'] = [OFFSET_X, OFFSET_Y + @object_count * STEP_Y, box['width'] || WIDTH, box['height'] || HEIGHT]
42
+ unless box['text'].nil?
43
+ box['text'] += " #{node.args}"
44
+ end
45
+
46
+ box
47
+ end
48
+
49
+ def make_line(parent_id, child_id)
50
+ { patchline: { destination: [child_id, 0], source: [parent_id, 0]} }
51
+ end
52
+ end
53
+ #
54
+ # Box = Struct.new( :id,
55
+ # :maxclass,
56
+ # :numinlets,
57
+ # :numoutlets,
58
+ # :outlettype,
59
+ # :patching_rect,
60
+ # :style,
61
+ # :text)
62
+ end
63
+ end
@@ -0,0 +1,54 @@
1
+ module Maxy
2
+ module Gen
3
+ class Parser
4
+ def initialize(tokens)
5
+ @tokens = tokens
6
+ end
7
+
8
+ def parse
9
+ parse_obj
10
+ end
11
+
12
+ def parse_obj(obj_node=nil)
13
+ return if @tokens.length == 0
14
+
15
+ obj_name = consume(:identifier).value
16
+ arguments = ''
17
+ if peek(:arguments)
18
+ arguments = parse_arguments
19
+ end
20
+
21
+ new_obj_node = ObjectNode.new(obj_name, arguments, [])
22
+ obj_node.child_nodes << new_obj_node unless obj_node.nil?
23
+
24
+ if peek(:dash)
25
+ consume(:dash)
26
+ parse_obj(new_obj_node)
27
+ end
28
+
29
+ new_obj_node
30
+ end
31
+
32
+ def parse_arguments
33
+ args = consume(:arguments)
34
+ args.value =~ /\A{([^{}]*)}\Z/
35
+ $1
36
+ end
37
+
38
+ def consume(expected_type)
39
+ token = @tokens.shift
40
+ if token.type == expected_type
41
+ token
42
+ else
43
+ raise RuntimeError.new("Expected token type #{expected_type.inspect}, but got #{token.type.inspect}")
44
+ end
45
+ end
46
+
47
+ def peek(expected_type)
48
+ @tokens.length > 0 && @tokens.fetch(0).type == expected_type
49
+ end
50
+ end
51
+
52
+ ObjectNode = Struct.new(:name, :args, :child_nodes)
53
+ end
54
+ end
@@ -0,0 +1,39 @@
1
+ module Maxy
2
+ module Gen
3
+ class Tokenizer
4
+ TOKEN_TYPES = [
5
+ [:arguments, /({[^{}]*})/],
6
+ [:escaped_identifier, /(\\[\S]+)(?=[-+{}])/],
7
+ [:identifier, /([^-+{}()\\]+)(?=[-+{}])?/],
8
+ [:dash, /(-)/]
9
+ ]
10
+
11
+ def initialize(pattern)
12
+ @pattern = pattern
13
+ end
14
+
15
+ def tokenize
16
+ tokens = []
17
+ until @pattern.empty?
18
+ tokens << tokenize_one_token
19
+ end
20
+ tokens
21
+ end
22
+
23
+ def tokenize_one_token
24
+ TOKEN_TYPES.each do |type, re|
25
+ re = /\A#{re}/
26
+ if @pattern =~ re
27
+ value = $1
28
+ @pattern = @pattern[value.length..-1]
29
+ return Token.new(type, value)
30
+ end
31
+ end
32
+
33
+ raise RuntimeError.new "Couldn't match token on #{@pattern.inspect}"
34
+ end
35
+ end
36
+
37
+ Token = Struct.new(:type, :value)
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Maxy
2
+ module Gen
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/maxy/gen.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "maxy/gen/version"
2
+ require 'maxy/gen/generator'
3
+ require 'maxy/gen/parser'
4
+ require 'maxy/gen/tokenizer'
data/maxy-gen.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'maxy/gen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "maxy-gen"
8
+ spec.version = Maxy::Gen::VERSION
9
+ spec.authors = ["Julian Rubisch"]
10
+ spec.email = ["julian@julianrubisch.at"]
11
+
12
+ spec.summary = %q{A commandline tool to generate max patches in an emmet-like fashion}
13
+ spec.description = %q{A commandline tool to generate max patches in an emmet-like fashion}
14
+ spec.homepage = "https://github.com/julianrubisch/maxy-gen"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "cucumber"
36
+ spec.add_development_dependency "aruba"
37
+
38
+ spec.add_dependency "thor"
39
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maxy-gen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julian Rubisch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
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: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A commandline tool to generate max patches in an emmet-like fashion
98
+ email:
99
+ - julian@julianrubisch.at
100
+ executables:
101
+ - maxy-gen
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - assets/blank.yml
113
+ - assets/library.yml
114
+ - bin/console
115
+ - bin/setup
116
+ - exe/maxy-gen
117
+ - lib/maxy/gen.rb
118
+ - lib/maxy/gen/cli.rb
119
+ - lib/maxy/gen/generator.rb
120
+ - lib/maxy/gen/parser.rb
121
+ - lib/maxy/gen/tokenizer.rb
122
+ - lib/maxy/gen/version.rb
123
+ - maxy-gen.gemspec
124
+ homepage: https://github.com/julianrubisch/maxy-gen
125
+ licenses: []
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.14
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A commandline tool to generate max patches in an emmet-like fashion
147
+ test_files: []