musa-dsl 0.26.2 → 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: f7f400c1a2c9841fc229ddb34343788eb688c4ab627e3f5ad8d4bcb57bd9ab90
4
- data.tar.gz: f0a0bf769dc19d17fc54818f83ca92174b223a503fb1f5145b996ac743bc0a1a
3
+ metadata.gz: 9d9154434fb485380e87cf24b6efa8ebdbaee0a223a94c2ad1988ae808b0a691
4
+ data.tar.gz: 6323750820c35c1ef1e8b2220d4f511bba9fafaf504dacadce14aba33ee647f2
5
5
  SHA512:
6
- metadata.gz: d35323bf0ef3686f839fcbdc4683fe3c7a05e9de99b4fab7a365f55576fd125704b52833bbea89bfae11db3c70d9d34a2fb2a2400252bd6fedf1d881483000ce
7
- data.tar.gz: bf02e13897e2441ce2d48c82a0ac9d1a2ba25ba244a22597597232710fb18efd688c8f5228fa94ef8956f9fea9818725c251d122dfe05086d4e745e1c745538c
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,13 +6,14 @@ 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)
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
 
15
15
  @logger = logger || Musa::Logger::Logger.new
16
+ @highlight_exception = highlight_exception
16
17
 
17
18
  @block_source = nil
18
19
 
@@ -38,7 +39,7 @@ module Musa
38
39
 
39
40
  when '#begin'
40
41
  user_path = buffer&.string
41
- @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
42
43
 
43
44
  buffer = StringIO.new
44
45
 
@@ -48,11 +49,11 @@ module Musa
48
49
 
49
50
  begin
50
51
  send_echo @block_source, output: @connection
51
- @binder.eval @block_source, "(repl)", 1
52
+ @bind.receiver.execute @block_source, '(repl)', 1
52
53
 
53
54
  rescue StandardError, ScriptError => e
54
55
  @logger.warn('REPL') { 'code execution error' }
55
- @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
56
+ @logger.warn('REPL') { e.full_message(highlight: @highlight_exception, order: :top) }
56
57
 
57
58
  send_exception e, output: @connection
58
59
  else
@@ -66,10 +67,10 @@ module Musa
66
67
 
67
68
  rescue IOError, Errno::ECONNRESET, Errno::EPIPE => e
68
69
  @logger.warn('REPL') { 'lost connection' }
69
- @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
70
+ @logger.warn('REPL') { e.full_message(highlight: @highlight_exception, order: :top) }
70
71
 
71
72
  ensure
72
- @logger.debug("REPL") { "closing connection (running #{@run})" }
73
+ @logger.debug('REPL') { "closing connection (running #{@run})" }
73
74
  @connection.close
74
75
  end
75
76
 
@@ -77,24 +78,24 @@ module Musa
77
78
  end
78
79
  rescue Errno::ECONNRESET, Errno::EPIPE => e
79
80
  @logger.warn('REPL') { 'connection failure while getting server port; will retry...' }
80
- @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
81
+ @logger.warn('REPL') { e.full_message(highlight: @highlight_exception, order: :top) }
81
82
  retry
82
83
 
83
84
  end
84
85
  end
85
86
  end
86
87
 
87
- def binder=(binder)
88
- raise 'Already binded' if @binder
88
+ def bind=(bind)
89
+ raise 'Already binded' if @bind
89
90
 
90
- @binder = binder
91
+ @bind = bind
91
92
 
92
- return unless @binder
93
+ return unless @bind
93
94
 
94
- if @binder.receiver.respond_to?(:sequencer) &&
95
- @binder.receiver.sequencer.respond_to?(:on_error)
95
+ if @bind.receiver.respond_to?(:sequencer) &&
96
+ @bind.receiver.sequencer.respond_to?(:on_error)
96
97
 
97
- @binder.receiver.sequencer.on_error do |e|
98
+ @bind.receiver.sequencer.on_error do |e|
98
99
  send_exception e, output: @connection
99
100
  end
100
101
  end
@@ -130,7 +131,7 @@ module Musa
130
131
 
131
132
  def send_exception(e, output:)
132
133
 
133
- @logger.error('REPL') { e.full_message(highlight: true, order: :top) }
134
+ @logger.error('REPL') { e.full_message(highlight: @highlight_exception, order: :top) }
134
135
 
135
136
  send output: output, command: '//error'
136
137
 
@@ -184,5 +185,15 @@ module Musa
184
185
  end
185
186
  end
186
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
187
198
  end
188
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.2'.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.2'
4
- s.date = '2021-11-25'
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.2
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: 2021-11-25 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