maxy-gen 0.2.1 → 0.2.2

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
  SHA256:
3
- metadata.gz: '0846a45c99b150ce94e07414b151a92c39ecee5a1dc90579b8397aeb1610df4f'
4
- data.tar.gz: 352e1f3a822491a204f507b16bf3547109fcd1e15c4e37c1c0c7ab95abec1e7a
3
+ metadata.gz: ddf1d556c1b563928dac5451b7e431034ab0265f1599a6f075c2fbe9cea47777
4
+ data.tar.gz: 29b360138505a3700dc6a38abc8ac989673a0bb0a42c18484733eccfe994b1eb
5
5
  SHA512:
6
- metadata.gz: eda407e64ce5503509f480eee9de4fc1f763ed26942ccdfa6f5911d78aa03623d886ab59c8b8f86d24a1719877b316c334da8eeebef0784546a8c2236dd7ce1d
7
- data.tar.gz: c5526a8d487134714b16cdd79b659fddda3bc22f6a26dc35852c3194216ea0d18693e79f8df1ba0cadd78edf1ace5ef8ff6965ba169604647e71235cc49e91ae
6
+ metadata.gz: 5930cfb96c88d5deb47e186f685dbb3cb113609cca68d4fae099e2a6ac854a21c12e41467eae434cb1523f0378554a6d5bef1a625c282b39ed341c0cf7833bb5
7
+ data.tar.gz: 3e55e67c6e5b0c246c4edb0be123f57cbf6b5c6fd0ace130cf4b67f0b68328576e9e6e4b88079e9fa306b3d62da7e1d8605a6a9fad23fd13880b92aca9b6b799
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maxy-gen (0.2.0)
4
+ maxy-gen (0.2.2)
5
5
  nokogiri
6
6
  thor
7
7
 
@@ -4,9 +4,9 @@ require 'psych'
4
4
  module Maxy
5
5
  module Gen
6
6
  class Generator
7
- TEMPLATE = Psych.load_file(File.join(__dir__, '../../../assets/blank.yml')).freeze
8
7
  OFFSET_X = 20
9
8
  OFFSET_Y = 20
9
+ STEP_X = 70
10
10
  STEP_Y = 40
11
11
  HEIGHT = 22
12
12
  WIDTH = 50
@@ -17,13 +17,14 @@ module Maxy
17
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
18
 
19
19
  @object_count = 1
20
- @patch = TEMPLATE.freeze
20
+ @patch = Psych.load_file(File.join(__dir__, '../../../assets/blank.yml')).freeze
21
21
  @library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").freeze
22
22
  end
23
23
 
24
24
  def generate(node)
25
25
  return JSON.generate(@patch) if node.nil?
26
26
 
27
+ node = align_tree(node)
27
28
  generate_node(node, "obj_#{@object_count}")
28
29
  JSON.generate(@patch)
29
30
  end
@@ -37,12 +38,13 @@ module Maxy
37
38
  generate_node(child_node, child_id)
38
39
  @patch['patcher']['lines'] << make_line(id, child_id)
39
40
  end
41
+
40
42
  end
41
43
 
42
44
  def make_box(node, id)
43
45
  box = @library[:objects][node.name]
44
46
  box['id'] = id
45
- box['patching_rect'] = [OFFSET_X, OFFSET_Y + @object_count * STEP_Y, box['width'] || WIDTH, box['height'] || HEIGHT]
47
+ box['patching_rect'] = [OFFSET_X + node.x_rank * STEP_X, OFFSET_Y + node.y_rank * STEP_Y, box['width'] || WIDTH, box['height'] || HEIGHT]
46
48
  unless box['text'].nil?
47
49
  box['text'] += " #{node.args}"
48
50
  end
@@ -53,15 +55,23 @@ module Maxy
53
55
  def make_line(parent_id, child_id)
54
56
  { patchline: { destination: [child_id, 0], source: [parent_id, 0]} }
55
57
  end
58
+
59
+ def align_tree(node, x_rank = 1, y_rank = 1)
60
+ node.x_rank = x_rank
61
+ node.y_rank = y_rank
62
+
63
+ y_rank += 1
64
+
65
+ node.child_nodes.each do |child|
66
+ align_tree(child, x_rank, y_rank)
67
+ x_rank += 1
68
+ end
69
+
70
+ node
71
+ end
56
72
  end
57
73
  #
58
- # Box = Struct.new( :id,
59
- # :maxclass,
60
- # :numinlets,
61
- # :numoutlets,
62
- # :outlettype,
63
- # :patching_rect,
64
- # :style,
65
- # :text)
74
+ # Box = Struct.new( :id, :node, :x_rank, :y_rank)
75
+
66
76
  end
67
77
  end
@@ -15,36 +15,26 @@ module Maxy
15
15
  def parse_obj(obj_node=nil)
16
16
  return if @tokens.length == 0
17
17
 
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
18
+ obj_name = parse_identifier
25
19
 
26
- raise RuntimeError.new("Could not find #{obj_name} in object definitions.") if @library[:objects][obj_name].nil?
27
-
28
- arguments = ''
29
- if peek(:arguments)
30
- arguments = parse_arguments
31
- end
20
+ arguments = parse_arguments || ''
32
21
 
33
22
  new_obj_node = ObjectNode.new(obj_name, arguments, [])
34
23
  obj_node.child_nodes << new_obj_node unless obj_node.nil?
35
24
 
36
- if peek(:dash)
37
- consume(:dash)
38
- parse_obj(new_obj_node)
39
- end
25
+ parse_plus(obj_node)
26
+
27
+ parse_dash(new_obj_node)
40
28
 
41
29
  new_obj_node
42
30
  end
43
31
 
44
32
  def parse_arguments
45
- args = consume(:arguments)
46
- args.value =~ /\A{([^{}]*)}\Z/
47
- $1
33
+ if peek(:arguments)
34
+ args = consume(:arguments)
35
+ args.value =~ /\A{([^{}]*)}\Z/
36
+ $1
37
+ end
48
38
  end
49
39
 
50
40
  def consume(expected_type)
@@ -59,8 +49,42 @@ module Maxy
59
49
  def peek(expected_type)
60
50
  @tokens.length > 0 && @tokens.fetch(0).type == expected_type
61
51
  end
52
+
53
+ def parse_identifier
54
+ if peek(:identifier)
55
+ obj_name = consume(:identifier).value
56
+ else
57
+ if peek(:escaped_identifier)
58
+ obj_name = consume(:escaped_identifier).value
59
+ end
60
+ end
61
+ raise RuntimeError.new("Could not find #{obj_name} in object definitions.") if @library[:objects][obj_name].nil?
62
+
63
+ obj_name
64
+ end
65
+
66
+ def parse_plus(obj_node)
67
+ if peek(:plus)
68
+ consume(:plus)
69
+ sibling_obj_name = parse_identifier
70
+ sibling_args = parse_arguments || ''
71
+ sibling_obj_node = ObjectNode.new(sibling_obj_name, sibling_args, [])
72
+ obj_node.child_nodes << sibling_obj_node
73
+
74
+ parse_plus(obj_node)
75
+
76
+ parse_dash(sibling_obj_node)
77
+ end
78
+ end
79
+
80
+ def parse_dash(obj_node)
81
+ if peek(:dash)
82
+ consume(:dash)
83
+ parse_obj(obj_node)
84
+ end
85
+ end
62
86
  end
63
87
 
64
- ObjectNode = Struct.new(:name, :args, :child_nodes)
88
+ ObjectNode = Struct.new(:name, :args, :child_nodes, :x_rank, :y_rank)
65
89
  end
66
90
  end
@@ -5,6 +5,7 @@ module Maxy
5
5
  [:arguments, /({[^{}]*})/],
6
6
  [:escaped_identifier, /(\\[\S][^-+{}()\\]+)(?=[-+*{}])?/],
7
7
  [:identifier, /([^-+{}()\\]+)(?=[-+*{}])?/],
8
+ [:plus, /(\+)/],
8
9
  [:dash, /(-)/]
9
10
  ]
10
11
 
@@ -1,5 +1,5 @@
1
1
  module Maxy
2
2
  module Gen
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  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.2.1
4
+ version: 0.2.2
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-05 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler