maxy-gen 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: 6544b65a84167acfcb482cfe7f86524bafd8cd3c
4
- data.tar.gz: 37c1356e292db87822fa7f51361c2b13b3e5c0f8
2
+ SHA256:
3
+ metadata.gz: 18b01a3a7a4bcf740f5e37429e3788908eb8ab0e3014d820246f84f312ea6bac
4
+ data.tar.gz: 1faa519a006291dca4f6ce83d826ee4be619d550936a5c2a6a19a83bb3443340
5
5
  SHA512:
6
- metadata.gz: c543c5183934c2fc99105118515a60340b8b0695889ddbbcfacf20363ea234f1e7ed724fd4a23ef16e90379c673fbe1f3d61ff08d4ca0d88f52c5c8c9151fb8a
7
- data.tar.gz: 57e90872d4b36183206526d12b480d9a876177ffe7e53fdb6a5002a3163d8626364fefd77c29873c319f1acb3ccb95d29e6eca67aaf90af199dd2d909104793f
6
+ metadata.gz: 1e5767968b0aa0bfd3d305b8b9a03953e0d46ee8bd8bbcc7ecfa66765c603f5780653153f5227cf2e17d9475609b5abe513962bf52e42e9f1456725d18e6c3a3
7
+ data.tar.gz: dd557899776137ee503c0e0da9839463b370366af5976bd5af297336c5994a96e4bbb84b7b6416414c64c68cc4887d6624320ba2d27ad278620983343ecda9f2
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maxy-gen (0.1.0)
4
+ maxy-gen (0.2.0)
5
+ nokogiri
5
6
  thor
6
7
 
7
8
  GEM
@@ -38,8 +39,11 @@ GEM
38
39
  diff-lcs (1.3)
39
40
  ffi (1.9.23)
40
41
  gherkin (5.1.0)
42
+ mini_portile2 (2.3.0)
41
43
  multi_json (1.13.1)
42
44
  multi_test (0.1.2)
45
+ nokogiri (1.8.2)
46
+ mini_portile2 (~> 2.3.0)
43
47
  rake (10.5.0)
44
48
  rspec (3.7.0)
45
49
  rspec-core (~> 3.7.0)
@@ -68,4 +72,4 @@ DEPENDENCIES
68
72
  rspec (~> 3.0)
69
73
 
70
74
  BUNDLED WITH
71
- 1.14.6
75
+ 1.16.2
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A commandline tool to generate max patches in an emmet-like fashion
4
4
 
5
+ ![](https://s3.eu-central-1.amazonaws.com/maxy-gen/maxygen-demo.gif)
6
+
5
7
  ## Installation
6
8
 
7
9
  Requires `ruby` installed, of course. This gem was built with v.2.3.3.
@@ -9,6 +11,18 @@ Requires `ruby` installed, of course. This gem was built with v.2.3.3.
9
11
  Install the gem:
10
12
 
11
13
  $ gem install maxy-gen
14
+
15
+ This version depends on your local Max installation. Install max object definitions like so:
16
+
17
+ $ maxy-gen install
18
+
19
+ Or simply
20
+
21
+ $ maxy-gen i
22
+
23
+ You will be asked for the path to your `refpages` directory. Just hit Enter if you installed Max in your Applications folder.
24
+
25
+ Note: This is totally untested on Windows!
12
26
 
13
27
  ## Usage
14
28
 
@@ -16,6 +30,7 @@ Use an [emmet](https://emmet.io/)-like pattern to generate a max patch, e.g.
16
30
 
17
31
  $ maxy-gen generate 'cycle~{440.}-*~{0.2}-ezdac~' > test.maxpat
18
32
 
33
+ (or shorter, `maxy-gen g ...`)
19
34
 
20
35
  ... and open it in Max.
21
36
 
@@ -24,21 +39,27 @@ As of now you can use
24
39
  - `-` dashes to indicate patch chords
25
40
  - `{}` curly braces to denote arguments passed to objects
26
41
 
27
- This gem is under heavy development and needs a library of max objects to function.
42
+ A couple of objects need escaping (with `\`), because some characters are taken, obviously. These are:
43
+
44
+ - `\-`
45
+ - `\+`
46
+ - `\*`
47
+ - `\-~`
48
+ - `\+=~`
49
+ - `\+~`
50
+ - `\*~`
28
51
 
29
- This early prototype supports
30
- - `cycle~`
31
- - `ezdac~`
32
- - `sig~`
33
- - `*~`
34
52
 
35
- - (later, you will be able to use escaped identifiers, such as `\-~`, because `-{}` are taken, obviously )
53
+
54
+ This gem is under heavy development!
36
55
 
37
56
  ## Contributing
38
57
 
39
58
  Bug reports and pull requests are welcome on GitHub at https://github.com/julianrubisch/maxy-gen.
40
59
 
41
60
  Please include:
61
+ - your platform
62
+ - your ruby version
42
63
  - a description of what didn't work
43
64
  - the patch produced by maxy-gen
44
65
  - the patch as you'd have expected it
data/lib/maxy/gen/cli.rb CHANGED
@@ -1,11 +1,16 @@
1
1
  require 'thor'
2
2
  require 'psych'
3
3
  require 'json'
4
+ require 'fileutils'
5
+ require 'nokogiri'
4
6
  require 'maxy/gen'
5
7
 
6
8
  module Maxy
7
9
  module Gen
8
10
  class CLI < Thor
11
+ map "g" => :generate
12
+ map "i" => :install
13
+
9
14
  desc "generate PATTERN", "Generates a Max Patch JSON from an emmet-style pattern"
10
15
  method_option :blank, aliases: "-b"
11
16
  def generate(pattern='')
@@ -16,6 +21,53 @@ module Maxy
16
21
 
17
22
  puts Generator.new.generate(tree)
18
23
  end
24
+
25
+ desc "install", "Generate max objects library from local maxref pages"
26
+ def install
27
+ library = {objects: {}}
28
+ maxref_xml_root = '/Applications/Max.app/Contents/Resources/C74/docs/refpages'
29
+
30
+ print "Path to Max Refpages [#{maxref_xml_root}]:"
31
+ case choice = $stdin.gets.chomp
32
+ when ''
33
+ when /\A.+/i
34
+ maxref_xml_root = choice
35
+ else fail "cannot understand `#{choice}'"
36
+ end
37
+
38
+ Dir.foreach(maxref_xml_root) do |mod|
39
+ next if mod =~ /\.\.?/
40
+ if File.directory?("#{maxref_xml_root}/#{mod}")
41
+ Dir.glob("#{maxref_xml_root}/#{mod}/*.maxref.xml").each do |maxref|
42
+ doc = File.open(maxref) { |f| Nokogiri::XML(f) }
43
+
44
+ obj_name = doc.xpath('//c74object/@name').to_s
45
+ inlets = doc.xpath('//inlet')
46
+ outlets = doc.xpath('//outlet')
47
+
48
+ library[:objects][obj_name] = {}
49
+ library[:objects][obj_name]['maxclass'] = 'newobj'
50
+ library[:objects][obj_name]['style'] = ''
51
+ library[:objects][obj_name]['text'] = obj_name
52
+ library[:objects][obj_name]['numinlets'] = inlets.size
53
+ library[:objects][obj_name]['numoutlets'] = outlets.size
54
+ end
55
+ end
56
+ end
57
+
58
+ library[:objects].select { |k,v| k.match?(/\A^[-+*{}].*/) }.each do |k,v|
59
+ key = "\\#{k}"
60
+ library[:objects][key] = library[:objects].delete k
61
+ end
62
+
63
+ unless File.directory?("#{ENV['HOME']}/.maxy-gen")
64
+ FileUtils.mkdir_p("#{ENV['HOME']}/.maxy-gen")
65
+ end
66
+ File.open("#{ENV['HOME']}/.maxy-gen/library.yml", 'w') {|f| f.write library.to_yaml }
67
+
68
+ print "Successfully installed max object definitions."
69
+
70
+ end
19
71
  end
20
72
  end
21
73
  end
@@ -5,16 +5,20 @@ module Maxy
5
5
  module Gen
6
6
  class Generator
7
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
8
  OFFSET_X = 20
10
9
  OFFSET_Y = 20
11
10
  STEP_Y = 40
12
11
  HEIGHT = 22
13
12
  WIDTH = 50
14
13
 
14
+ attr_accessor :library
15
+
15
16
  def initialize
17
+ raise RuntimeError.new('No object definitions were found. please run `maxy-gen install` first') unless File.exist?("#{ENV['HOME']}/.maxy-gen/library.yml")
18
+
16
19
  @object_count = 1
17
20
  @patch = TEMPLATE.freeze
21
+ @library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").freeze
18
22
  end
19
23
 
20
24
  def generate(node)
@@ -36,7 +40,7 @@ module Maxy
36
40
  end
37
41
 
38
42
  def make_box(node, id)
39
- box = LIBRARY['objects'][node.name]
43
+ box = @library[:objects][node.name]
40
44
  box['id'] = id
41
45
  box['patching_rect'] = [OFFSET_X, OFFSET_Y + @object_count * STEP_Y, box['width'] || WIDTH, box['height'] || HEIGHT]
42
46
  unless box['text'].nil?
@@ -2,6 +2,9 @@ module Maxy
2
2
  module Gen
3
3
  class Parser
4
4
  def initialize(tokens)
5
+ raise RuntimeError.new('No object definitions were found. please run `maxy-gen install` first') unless File.exist?("#{ENV['HOME']}/.maxy-gen/library.yml")
6
+
7
+ @library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").freeze
5
8
  @tokens = tokens
6
9
  end
7
10
 
@@ -12,7 +15,16 @@ module Maxy
12
15
  def parse_obj(obj_node=nil)
13
16
  return if @tokens.length == 0
14
17
 
15
- obj_name = consume(:identifier).value
18
+ if peek(:identifier)
19
+ obj_name = consume(:identifier).value
20
+ else
21
+ if peek(:escaped_identifier)
22
+ obj_name = consume(:escaped_identifier).value
23
+ end
24
+ end
25
+
26
+ raise RuntimeError.new("Could not find #{obj_name} in object definitions.") if @library[:objects][obj_name].nil?
27
+
16
28
  arguments = ''
17
29
  if peek(:arguments)
18
30
  arguments = parse_arguments
@@ -3,8 +3,8 @@ module Maxy
3
3
  class Tokenizer
4
4
  TOKEN_TYPES = [
5
5
  [:arguments, /({[^{}]*})/],
6
- [:escaped_identifier, /(\\[\S]+)(?=[-+{}])/],
7
- [:identifier, /([^-+{}()\\]+)(?=[-+{}])?/],
6
+ [:escaped_identifier, /(\\[\S]+)(?=[-+*{}])/],
7
+ [:identifier, /([^-+{}()\\]+)(?=[-+*{}])?/],
8
8
  [:dash, /(-)/]
9
9
  ]
10
10
 
@@ -1,5 +1,5 @@
1
1
  module Maxy
2
2
  module Gen
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/maxy-gen.gemspec CHANGED
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "aruba"
37
37
 
38
38
  spec.add_dependency "thor"
39
+ spec.add_dependency "nokogiri"
39
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxy-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Rubisch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: A commandline tool to generate max patches in an emmet-like fashion
98
112
  email:
99
113
  - julian@julianrubisch.at
@@ -104,13 +118,13 @@ extra_rdoc_files: []
104
118
  files:
105
119
  - ".gitignore"
106
120
  - ".rspec"
121
+ - ".ruby-version"
107
122
  - ".travis.yml"
108
123
  - Gemfile
109
124
  - Gemfile.lock
110
125
  - README.md
111
126
  - Rakefile
112
127
  - assets/blank.yml
113
- - assets/library.yml
114
128
  - bin/console
115
129
  - bin/setup
116
130
  - exe/maxy-gen
@@ -140,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
154
  version: '0'
141
155
  requirements: []
142
156
  rubyforge_project:
143
- rubygems_version: 2.6.14
157
+ rubygems_version: 2.7.6
144
158
  signing_key:
145
159
  specification_version: 4
146
160
  summary: A commandline tool to generate max patches in an emmet-like fashion
data/assets/library.yml DELETED
@@ -1,32 +0,0 @@
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: "*~"