musa-dsl 0.21.3 → 0.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cc5aa748a51c09ce12d7ad6b17a7922d87d56742a7a03c61753e5cf05e0faac
4
- data.tar.gz: a34656b54c6ed0997e897c8919c04e6361b85501b6c17d48b3df79797943d376
3
+ metadata.gz: dae00405142514f16df2be12de1eb9327893f3996ad3c86ec76fc315db521e7d
4
+ data.tar.gz: f3ebf69b72452ab83ec33ab873221ee1f0d59954e2c67277c2386fc174278a7c
5
5
  SHA512:
6
- metadata.gz: 740ea84da6d43d290f970d4bf64d5634c80044d1be2a59508543c288dd86ed4550e990a4cedb5c1cda5a0e8c551bc1f6cf7e3625bba9748df1f438bafeb5b008
7
- data.tar.gz: 4876305d8c5a27924796f29667fc2f4db73ef753646e561ca12b9ac2772f0dc9cf14df4996867bf64aa11af6792d0c4bfd7a423001d163a1e9afd8e943ab5db4
6
+ metadata.gz: 006f3143b93237b86600bde3b7229f14cae909a50603af4c0d1f33050835c582988325f8b2db63b74d20826d1682f09d51960e32d977f47ce86d69b4d25cd53b
7
+ data.tar.gz: 7c07575e0bcf7a2b5f9e6361d8ae2b64193b8bba31bec3badfbf02f8c83f8a3595bc84df42aa6c8976c947528c82752f9869ed7c19240c9d0d536cb435b4da86
@@ -39,6 +39,7 @@ module Musa
39
39
  case line
40
40
  when '#begin'
41
41
  buffer = StringIO.new
42
+
42
43
  when '#end'
43
44
  @@repl_mutex.synchronize do
44
45
  @block_source = buffer.string
@@ -48,8 +49,8 @@ module Musa
48
49
  binder.eval @block_source, "(repl)", 1
49
50
 
50
51
  rescue StandardError, ScriptError => e
51
- @logger.debug('REPL') { 'code execution error' }
52
- @logger.debug('REPL') { e.full_message(highlight: true, order: :top) }
52
+ @logger.warn('REPL') { 'code execution error' }
53
+ @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
53
54
 
54
55
  send_exception e, output: @connection
55
56
  else
@@ -65,12 +66,6 @@ module Musa
65
66
  @logger.warn('REPL') { 'lost connection' }
66
67
  @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
67
68
 
68
- rescue Exception, SystemExit, Interrupt
69
- puts "EXCEPTION / SYSTEM EXIT / INTERUPT"
70
- $stdout.flush
71
- @logger.warn('REPL') { 'received interruption; will close connection...' }
72
- raise
73
-
74
69
  ensure
75
70
  @logger.debug("REPL") { "closing connection (running #{@run})" }
76
71
  @connection.close
@@ -92,6 +87,7 @@ module Musa
92
87
 
93
88
  @main_thread.terminate
94
89
  Thread.pass
90
+
95
91
  @main_thread = nil
96
92
 
97
93
  @client_threads.each { |t| t.terminate; Thread.pass }
@@ -13,7 +13,7 @@ module Musa
13
13
  when :neumalang
14
14
  NeumalangModePlayEval.new block_procedure_binder, decoder, nl_context
15
15
  else
16
- raise ArgumentError, "Mode #{mode} not allowed"
16
+ raise ArgumentError, "Unknown mode #{mode}"
17
17
  end
18
18
  end
19
19
 
@@ -66,7 +66,7 @@ module Musa
66
66
  @timeslots[at_position] << value
67
67
  end
68
68
  else
69
- _log "BaseSequencer._raw_numeric_at: warning: ignoring past at command for #{at_position}" if @do_log
69
+ @logger.warn('BaseSequencer') { "._raw_numeric_at: warning: ignoring past at command for #{at_position}" }
70
70
  end
71
71
 
72
72
  nil
@@ -90,7 +90,7 @@ module Musa
90
90
  key_parameters[:control] = control if block_key_parameters_binder.key?(:control)
91
91
 
92
92
  if at_position == @position
93
- @debug_at.call if debug && @debug_at
93
+ @on_debug_at.each { |c| c.call } if @logger.sev_threshold >= ::Logger::Severity::DEBUG
94
94
 
95
95
  begin
96
96
  locked = @tick_mutex.try_lock
@@ -103,13 +103,17 @@ module Musa
103
103
 
104
104
  @timeslots[at_position] ||= []
105
105
 
106
- @timeslots[at_position] << { parent_control: control, block: @on_debug_at } if debug && @on_debug_at
106
+ if @logger.sev_threshold <= ::Logger::Severity::DEBUG
107
+ @on_debug_at.each do |block|
108
+ @timeslots[at_position] << { parent_control: control, block: block }
109
+ end
110
+ end
107
111
 
108
112
  @timeslots[at_position] << { parent_control: control, block: block_key_parameters_binder,
109
113
  value_parameters: value_parameters,
110
114
  key_parameters: key_parameters }
111
115
  else
112
- _log "BaseSequencer._numeric_at: warning: ignoring past 'at' command for #{at_position}" if @do_log
116
+ @logger.warn('BaseSequencer') { "._numeric_at: warning: ignoring past 'at' command for #{at_position}" }
113
117
  end
114
118
 
115
119
  nil
@@ -661,10 +665,8 @@ module Musa
661
665
  end
662
666
 
663
667
  def _rescue_error(e)
664
- if @do_error_log
665
- log e
666
- log e.full_message(order: :top)
667
- end
668
+ @logger.error('BaseSequencer') { e.to_s }
669
+ @logger.error('BaseSequencer') { e.full_message(highlight: true, order: :top) }
668
670
 
669
671
  @on_error.each do |block|
670
672
  block.call e
@@ -48,11 +48,9 @@ module Musa
48
48
  original_position = position
49
49
  position = ticks_position.round * @tick_duration
50
50
 
51
- if @do_log
52
- _log "BaseSequencer._numeric_at: warning: rounding "\
53
- "position #{position} (#{original_position.to_f.round(5)}) "\
54
- "to tick precision: #{position} (#{position.to_f.round(5)})"
55
- end
51
+ @logger.warn('BaseSequencer') { "._numeric_at: warning: rounding "\
52
+ "position #{position} (#{original_position.to_f.round(5)}) "\
53
+ "to tick precision: #{position} (#{position.to_f.round(5)})" }
56
54
  end
57
55
 
58
56
  position
@@ -4,13 +4,20 @@ require 'nibbler'
4
4
  module Musa
5
5
  module Clock
6
6
  class InputMidiClock < Clock
7
- def initialize(input, do_log: nil)
7
+ def initialize(input, logger: nil, do_log: nil)
8
8
  do_log ||= false
9
9
 
10
10
  super()
11
11
 
12
12
  @input = input
13
- @do_log = do_log
13
+ @logger = logger
14
+
15
+ if logger
16
+ @logger = logger
17
+ else
18
+ @logger = Musa::Logger::Logger.new
19
+ @logger.debug! if do_log
20
+ end
14
21
 
15
22
  @nibbler = Nibbler.new
16
23
  end
@@ -52,7 +59,7 @@ module Musa
52
59
  messages[index + 1].name == 'Song Position Pointer' &&
53
60
  messages[index + 2].name == 'Continue'
54
61
 
55
- warn 'InputMidiClock: processing Stop + Song Position Pointer + Continue...' if @do_log
62
+ @logger.debug('InputMidiClock') { 'processing Stop + Song Position Pointer + Continue...' }
56
63
 
57
64
  process_start unless @started
58
65
 
@@ -62,7 +69,7 @@ module Musa
62
69
 
63
70
  index += 2
64
71
 
65
- warn 'InputMidiClock: processing Stop + Song Position Pointer + Continue... done' if @do_log
72
+ @logger.debug('InputMidiClock') { 'processing Stop + Song Position Pointer + Continue... done' }
66
73
 
67
74
  else
68
75
  process_message messages[index] do
@@ -84,12 +91,12 @@ module Musa
84
91
  private
85
92
 
86
93
  def process_start
87
- warn 'InputMidiClock: processing Start...' if @do_log
94
+ @logger.debug('InputMidiClock') { 'processing Start...' }
88
95
 
89
96
  @on_start.each(&:call)
90
97
  @started = true
91
98
 
92
- warn 'InputMidiClock: processing Start... done' if @do_log
99
+ @logger.debug('InputMidiClock') { 'processing Start... done' }
93
100
  end
94
101
 
95
102
  def process_message(m)
@@ -98,16 +105,16 @@ module Musa
98
105
  process_start
99
106
 
100
107
  when 'Stop'
101
- warn 'InputMidiClock: processing Stop...' if @do_log
108
+ @logger.debug('InputMidiClock') { 'processing Stop...' }
102
109
 
103
110
  @on_stop.each(&:call)
104
111
  @started = false
105
112
 
106
- warn 'InputMidiClock: processing Stop... done' if @do_log
113
+ @logger.debug('InputMidiClock') { 'processing Stop... done' }
107
114
 
108
115
  when 'Continue'
109
- warn 'InputMidiClock: processing Continue...' if @do_log
110
- warn 'InputMidiClock: processing Continue... done' if @do_log
116
+ @logger.debug('InputMidiClock') { 'processing Continue...' }
117
+ @logger.debug('InputMidiClock') { 'processing Continue... done' }
111
118
 
112
119
  when 'Clock'
113
120
  yield if block_given? && @started
@@ -116,9 +123,9 @@ module Musa
116
123
  new_position_in_midi_beats =
117
124
  m.data[0] & 0x7F | ((m.data[1] & 0x7F) << 7)
118
125
 
119
- warn "InputMidiClock: processing Song Position Pointer new_position_in_midi_beats #{new_position_in_midi_beats}..." if @do_log
126
+ @logger.debug('InputMidiClock') { "processing Song Position Pointer new_position_in_midi_beats #{new_position_in_midi_beats}..." }
120
127
  @on_change_position.each { |block| block.call midi_beats: new_position_in_midi_beats }
121
- warn "InputMidiClock: processing Song Position Pointer new_position_in_beats #{new_position_in_midi_beats}... done" if @do_log
128
+ @logger.debug('InputMidiClock') { "processing Song Position Pointer new_position_in_beats #{new_position_in_midi_beats}... done" }
122
129
  end
123
130
  end
124
131
  end
@@ -126,21 +126,21 @@ module Musa
126
126
  private
127
127
 
128
128
  def do_before_begin
129
- logger.debug('Transport') { 'doing before_begin initialization...' unless @before_begin.empty? }
129
+ logger.debug('Transport') { 'doing before_begin initialization...' } unless @before_begin.empty?
130
130
  @before_begin.each { |block| block.call @sequencer }
131
- logger.debug('Transport') { 'doing before_begin initialization... done' unless @before_begin.empty? }
131
+ logger.debug('Transport') { 'doing before_begin initialization... done' } unless @before_begin.empty?
132
132
  end
133
133
 
134
134
  def do_on_start
135
- logger.debug('Transport') { 'starting...' unless @on_start.empty? }
135
+ logger.debug('Transport') { 'starting...' } unless @on_start.empty?
136
136
  @on_start.each { |block| block.call @sequencer }
137
- logger.debug('Transport') { 'starting... done' unless @on_start.empty? }
137
+ logger.debug('Transport') { 'starting... done' } unless @on_start.empty?
138
138
  end
139
139
 
140
140
  def do_stop
141
- logger.debug('Transport') { 'stopping...' unless @after_stop.empty? }
141
+ logger.debug('Transport') { 'stopping...' } unless @after_stop.empty?
142
142
  @after_stop.each { |block| block.call @sequencer }
143
- logger.debug('Transport') { 'stopping... done' unless @after_stop.empty? }
143
+ logger.debug('Transport') { 'stopping... done' } unless @after_stop.empty?
144
144
 
145
145
  logger.debug('Transport') { 'resetting sequencer...' }
146
146
  @sequencer.reset
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'musa-dsl'
3
- s.version = '0.21.3'
3
+ s.version = '0.21.4'
4
4
  s.date = '2020-10-20'
5
5
  s.summary = 'A simple Ruby DSL for making complex music'
6
6
  s.description = 'Musa-DSL: A Ruby DSL for algorithmic music composition, device language neutral (MIDI, OSC, etc)'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musa-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.3
4
+ version: 0.21.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Sánchez Yeste