musa-dsl 0.26.4 → 0.26.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
  SHA256:
3
- metadata.gz: 0631b9bf8dbc0fedbfe7c00bdc5c4da34c3b319ade3de83fa49d08f7b95ea9b0
4
- data.tar.gz: 1c258db1cd5105a794e9cbfec73e12fc8e6ec3565395d25c234ec3ac0aed5d28
3
+ metadata.gz: 9d9154434fb485380e87cf24b6efa8ebdbaee0a223a94c2ad1988ae808b0a691
4
+ data.tar.gz: 6323750820c35c1ef1e8b2220d4f511bba9fafaf504dacadce14aba33ee647f2
5
5
  SHA512:
6
- metadata.gz: 86068de4a4b03eb6615438863fe62302b8d4c899058bf1faba5d2aef00608b91bb61b0a54775736ecf99b7ad91a9b765085f68201daeba537df042634f806c97
7
- data.tar.gz: bd321b8c0d140557fd2a747f5e1d8ecdf9335e6865abfc4d1cce2182e6493dd4e8983f0cdc208beefd91f098f589ff566afa33dcb534e7549d1a1e11609b0e8e
6
+ metadata.gz: 91e4c3067db836ae8eac4f0242bb4ac1dd6ee48da8959bb4f06b8133e49065260bf316d04dc893c1e2e9cd7f1cbf57b882167868ca3f27072869f15de9962424
7
+ data.tar.gz: d0df67a8d02ce6ab12764cfd2478de3322a3006ada484bbbe32cef0e885eac35be2d157fda16ee7453db7b314bb93f81cb46bf83409b218b6936e673c1e4dc2a
@@ -3,22 +3,22 @@ require_relative 'smart-proc-binder'
3
3
  module Musa
4
4
  module Extension
5
5
  module With
6
- def with(*value_parameters, **key_parameters, &block)
7
- binder = Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
6
+ def with(*value_parameters, keep_block_context: nil, **key_parameters, &block)
7
+ smart_block = Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
8
8
 
9
- send_self_as_underscore_parameter = binder.parameters[0][1] == :_ unless binder.parameters.empty?
9
+ send_self_as_underscore_parameter = smart_block.parameters[0][1] == :_ unless smart_block.parameters.empty?
10
10
 
11
- keep_proc_context = @keep_proc_context_on_with
12
- keep_proc_context ||= send_self_as_underscore_parameter
13
- keep_proc_context ||= false
11
+ effective_keep_block_context = keep_block_context
12
+ effective_keep_block_context = send_self_as_underscore_parameter if effective_keep_block_context.nil?
13
+ effective_keep_block_context = false if effective_keep_block_context.nil?
14
14
 
15
- effective_value_parameters, effective_key_parameters = binder._apply(value_parameters, key_parameters)
15
+ effective_value_parameters, effective_key_parameters = smart_block._apply(value_parameters, key_parameters)
16
16
 
17
- if keep_proc_context
17
+ if effective_keep_block_context
18
18
  if send_self_as_underscore_parameter
19
- binder.call(self, *effective_value_parameters, **effective_key_parameters)
19
+ smart_block.call(self, *effective_value_parameters, **effective_key_parameters)
20
20
  else
21
- binder.call(*effective_value_parameters, **effective_key_parameters)
21
+ smart_block.call(*effective_value_parameters, **effective_key_parameters)
22
22
  end
23
23
  elsif effective_value_parameters.empty? && effective_key_parameters.empty?
24
24
  instance_eval &block
@@ -1,17 +1,15 @@
1
1
  require_relative 'chord-definition'
2
2
 
3
- include Musa::Chords
3
+ Musa::Chords::ChordDefinition.register :maj, quality: :major, size: :triad, offsets: { root: 0, third: 4, fifth: 7 }
4
+ Musa::Chords::ChordDefinition.register :min, quality: :minor, size: :triad, offsets: { root: 0, third: 3, fifth: 7 }
4
5
 
5
- ChordDefinition.register :maj, quality: :major, size: :triad, offsets: { root: 0, third: 4, fifth: 7 }
6
- ChordDefinition.register :min, quality: :minor, size: :triad, offsets: { root: 0, third: 3, fifth: 7 }
6
+ Musa::Chords::ChordDefinition.register :maj7, quality: :major, size: :seventh, offsets: { root: 0, third: 4, fifth: 7, seventh: 11 }
7
+ Musa::Chords::ChordDefinition.register :maj7, quality: :major, size: :seventh, dominant: :dominant , offsets: { root: 0, third: 4, fifth: 7, seventh: 10 }
7
8
 
8
- ChordDefinition.register :maj7, quality: :major, size: :seventh, offsets: { root: 0, third: 4, fifth: 7, seventh: 11 }
9
- ChordDefinition.register :maj7, quality: :major, size: :seventh, dominant: :dominant , offsets: { root: 0, third: 4, fifth: 7, seventh: 10 }
9
+ Musa::Chords::ChordDefinition.register :min7, quality: :minor, size: :seventh, offsets: { root: 0, third: 3, fifth: 7, seventh: 11 }
10
10
 
11
- ChordDefinition.register :min7, quality: :minor, size: :seventh, offsets: { root: 0, third: 3, fifth: 7, seventh: 11 }
11
+ Musa::Chords::ChordDefinition.register :maj9, quality: :major, size: :ninth, offsets: { root: 0, third: 4, fifth: 7, seventh: 11, ninth: 14 }
12
+ Musa::Chords::ChordDefinition.register :min9, quality: :minor, size: :ninth, offsets: { root: 0, third: 3, fifth: 7, seventh: 11, ninth: 14 }
12
13
 
13
- ChordDefinition.register :maj9, quality: :major, size: :ninth, offsets: { root: 0, third: 4, fifth: 7, seventh: 11, ninth: 14 }
14
- ChordDefinition.register :min9, quality: :minor, size: :ninth, offsets: { root: 0, third: 3, fifth: 7, seventh: 11, ninth: 14 }
15
-
16
- ChordDefinition.register :maj11, quality: :major, size: :eleventh, offsets: { root: 0, third: 4, fifth: 7, seventh: 11, ninth: 14, eleventh: 17 }
17
- ChordDefinition.register :min11, quality: :minor, size: :eleventh, offsets: { root: 0, third: 3, fifth: 7, seventh: 11, ninth: 14, eleventh: 17 }
14
+ Musa::Chords::ChordDefinition.register :maj11, quality: :major, size: :eleventh, offsets: { root: 0, third: 4, fifth: 7, seventh: 11, ninth: 14, eleventh: 17 }
15
+ Musa::Chords::ChordDefinition.register :min11, quality: :minor, size: :eleventh, offsets: { root: 0, third: 3, fifth: 7, seventh: 11, ninth: 14, eleventh: 17 }
@@ -6,9 +6,9 @@ module Musa
6
6
  class REPL
7
7
  @@repl_mutex = Mutex.new
8
8
 
9
- def initialize(binder = nil, port: nil, after_eval: nil, logger: nil, highlight_exception: true)
9
+ def initialize(bind = nil, port: nil, after_eval: nil, logger: nil, highlight_exception: true)
10
10
 
11
- self.binder = binder
11
+ self.bind = bind
12
12
 
13
13
  port ||= 1327
14
14
 
@@ -39,7 +39,7 @@ module Musa
39
39
 
40
40
  when '#begin'
41
41
  user_path = buffer&.string
42
- @binder.receiver.instance_variable_set(:@user_pathname, Pathname.new(user_path)) if user_path
42
+ @bind.receiver.instance_variable_set(:@user_pathname, Pathname.new(user_path)) if user_path
43
43
 
44
44
  buffer = StringIO.new
45
45
 
@@ -49,7 +49,7 @@ module Musa
49
49
 
50
50
  begin
51
51
  send_echo @block_source, output: @connection
52
- @binder.eval @block_source, "(repl)", 1
52
+ @bind.receiver.execute @block_source, '(repl)', 1
53
53
 
54
54
  rescue StandardError, ScriptError => e
55
55
  @logger.warn('REPL') { 'code execution error' }
@@ -70,7 +70,7 @@ module Musa
70
70
  @logger.warn('REPL') { e.full_message(highlight: @highlight_exception, order: :top) }
71
71
 
72
72
  ensure
73
- @logger.debug("REPL") { "closing connection (running #{@run})" }
73
+ @logger.debug('REPL') { "closing connection (running #{@run})" }
74
74
  @connection.close
75
75
  end
76
76
 
@@ -85,17 +85,17 @@ module Musa
85
85
  end
86
86
  end
87
87
 
88
- def binder=(binder)
89
- raise 'Already binded' if @binder
88
+ def bind=(bind)
89
+ raise 'Already binded' if @bind
90
90
 
91
- @binder = binder
91
+ @bind = bind
92
92
 
93
- return unless @binder
93
+ return unless @bind
94
94
 
95
- if @binder.receiver.respond_to?(:sequencer) &&
96
- @binder.receiver.sequencer.respond_to?(:on_error)
95
+ if @bind.receiver.respond_to?(:sequencer) &&
96
+ @bind.receiver.sequencer.respond_to?(:on_error)
97
97
 
98
- @binder.receiver.sequencer.on_error do |e|
98
+ @bind.receiver.sequencer.on_error do |e|
99
99
  send_exception e, output: @connection
100
100
  end
101
101
  end
@@ -185,5 +185,15 @@ module Musa
185
185
  end
186
186
  end
187
187
  end
188
+
189
+ module CustomizableDSLContext
190
+ protected def binder
191
+ raise NotImplementedError, 'Binder method should be implemented in target namespace as def binder; @__binder ||= binding; end'
192
+ end
193
+
194
+ def execute(source_block, file, line)
195
+ binder.eval source_block, file, line
196
+ end
197
+ end
188
198
  end
189
199
  end
@@ -2,6 +2,8 @@ require 'forwardable'
2
2
 
3
3
  require_relative '../core-ext/with'
4
4
 
5
+ module TEMP; end
6
+
5
7
  module Musa
6
8
  module Sequencer
7
9
  class Sequencer
@@ -28,7 +30,8 @@ module Musa
28
30
  sequencer: nil,
29
31
  logger: nil,
30
32
  do_log: nil, do_error_log: nil, log_position_format: nil,
31
- keep_proc_context: nil,
33
+ dsl_context_class: nil,
34
+ keep_block_context: nil,
32
35
  &block)
33
36
 
34
37
  @sequencer = sequencer
@@ -38,7 +41,9 @@ module Musa
38
41
  do_error_log: do_error_log,
39
42
  log_position_format: log_position_format
40
43
 
41
- @dsl = DSLContext.new @sequencer, keep_proc_context: keep_proc_context
44
+ # dsl_context_class ||= DSLContext
45
+
46
+ @dsl = dsl_context_class.new @sequencer, keep_block_context: keep_block_context
42
47
 
43
48
  @dsl.with &block if block_given?
44
49
  end
@@ -61,16 +66,16 @@ module Musa
61
66
  :ticks_per_bar, :logger, :debug, :inspect,
62
67
  :run
63
68
 
64
- def initialize(sequencer, keep_proc_context:)
69
+ def initialize(sequencer, keep_block_context:)
65
70
  @sequencer = sequencer
66
- @keep_proc_context_on_with = keep_proc_context
71
+ @keep_block_context_on_with = keep_block_context
67
72
  end
68
73
 
69
74
  def now(*value_parameters, **key_parameters, &block)
70
75
  block ||= proc {}
71
76
 
72
77
  @sequencer.now *value_parameters, **key_parameters do |*value_args, **key_args|
73
- with *value_args, **key_args, &block
78
+ with *value_args, **key_args, keep_block_context: @keep_block_context_on_with, &block
74
79
  end
75
80
  end
76
81
 
@@ -78,14 +83,14 @@ module Musa
78
83
  block ||= proc {}
79
84
 
80
85
  @sequencer.at *value_parameters, **key_parameters do |*value_args, **key_args|
81
- with *value_args, **key_args, &block
86
+ with *value_args, **key_args, keep_block_context: @keep_block_context_on_with, &block
82
87
  end
83
88
  end
84
89
 
85
90
  def wait(*value_parameters, **key_parameters, &block)
86
91
  block ||= proc {}
87
- @sequencer.wait *value_parameters, **key_parameters do | *values, **key_values |
88
- with *values, **key_values, &block
92
+ @sequencer.wait *value_parameters, **key_parameters do |*values, **key_values|
93
+ with *values, **key_values, keep_block_context: @keep_block_context_on_with, &block
89
94
  end
90
95
  end
91
96
 
@@ -93,7 +98,7 @@ module Musa
93
98
  block ||= proc {}
94
99
 
95
100
  @sequencer.play *value_parameters, **key_parameters do |*value_args, **key_args|
96
- with *value_args, **key_args, &block
101
+ with *value_args, **key_args, keep_block_context: @keep_block_context_on_with, &block
97
102
  end
98
103
  end
99
104
 
@@ -101,7 +106,7 @@ module Musa
101
106
  block ||= proc {}
102
107
 
103
108
  @sequencer.play_timed *value_parameters, **key_parameters do |*value_args, **key_args|
104
- with *value_args, **key_args, &block
109
+ with *value_args, **key_args, keep_block_context: @keep_block_context_on_with, &block
105
110
  end
106
111
  end
107
112
 
@@ -110,7 +115,7 @@ module Musa
110
115
 
111
116
  @sequencer.every *value_parameters, **key_parameters do |*value_args, **key_args|
112
117
  args = Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)._apply(value_args, key_args)
113
- with *args.first, **args.last, &block
118
+ with *args.first, **args.last, keep_block_context: @keep_block_context_on_with, &block
114
119
  end
115
120
  end
116
121
 
@@ -118,12 +123,10 @@ module Musa
118
123
  block ||= proc {}
119
124
 
120
125
  @sequencer.move *value_parameters, **key_parameters do |*value_args, **key_args|
121
- with *value_args, **key_args, &block
126
+ with *value_args, **key_args, keep_block_context: @keep_block_context_on_with, &block
122
127
  end
123
128
  end
124
129
  end
125
-
126
- private_constant :DSLContext
127
130
  end
128
131
  end
129
132
  end
data/lib/musa-dsl.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Musa
2
- VERSION = '0.26.4'.freeze
2
+ VERSION = '0.26.5'.freeze
3
3
  end
4
4
 
5
5
  require_relative 'musa-dsl/core-ext'
data/musa-dsl.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'musa-dsl'
3
- s.version = '0.26.4'
4
- s.date = '2022-02-17'
3
+ s.version = '0.26.5'
4
+ s.date = '2022-02-25'
5
5
  s.summary = 'A simple Ruby DSL for making complex music'
6
6
  s.description = 'Musa-DSL: A Ruby framework and DSL for algorithmic sound and musical thinking and composition'
7
7
  s.authors = ['Javier Sánchez Yeste']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musa-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.4
4
+ version: 0.26.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Sánchez Yeste
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-17 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger