musa-dsl 0.21.1 → 0.21.3

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: f6666b6d9729d138be960000a3dd86a517f9ed94031d74a6eab25b76052d45c5
4
- data.tar.gz: a6806869e3f06e54bc5596f71c35cfff8a9513504653a889e57287d227990419
3
+ metadata.gz: 5cc5aa748a51c09ce12d7ad6b17a7922d87d56742a7a03c61753e5cf05e0faac
4
+ data.tar.gz: a34656b54c6ed0997e897c8919c04e6361b85501b6c17d48b3df79797943d376
5
5
  SHA512:
6
- metadata.gz: 531fbb701e5774e11a1a1dc373308fada1f777c6b8c7981e8a27ffd1ddb3c242bc1e5723555553010d4ff10259c7c69cd2e2428b9d0eab65ef96ae8b13b14f7b
7
- data.tar.gz: c2db1fae44b49ee11fd8dd5d764dee4c7416c4b7fb6ce075213f84207d54cd7b5cc6301f59a74a723b467a103c74c779f68f9a946c0fcdd92fefbe77d26758c0
6
+ metadata.gz: 740ea84da6d43d290f970d4bf64d5634c80044d1be2a59508543c288dd86ed4550e990a4cedb5c1cda5a0e8c551bc1f6cf7e3625bba9748df1f438bafeb5b008
7
+ data.tar.gz: 4876305d8c5a27924796f29667fc2f4db73ef753646e561ca12b9ac2772f0dc9cf14df4996867bf64aa11af6792d0c4bfd7a423001d163a1e9afd8e943ab5db4
@@ -9,7 +9,7 @@ module Musa; module Logger
9
9
  @position_format = position_format || 3.3
10
10
 
11
11
  self.formatter = proc do |severity, time, progname, msg|
12
- level = "[#{severity}]" unless severity == 'DEBUG'
12
+ level = "[#{severity}] " unless severity == 'DEBUG'
13
13
 
14
14
  if msg
15
15
  position = if @sequencer
@@ -19,7 +19,7 @@ module Musa; module Logger
19
19
  "%#{integer_digits + decimal_digits + 1}s: " % ("%.#{decimal_digits}f" % sequencer.position.to_f)
20
20
  end
21
21
 
22
- progname = "[#{progname}]" if progname
22
+ progname = "[#{progname}] " if progname
23
23
 
24
24
  "#{position}#{level}#{progname}#{msg}\n"
25
25
  else
@@ -2,6 +2,10 @@ require 'set'
2
2
  require 'midi-message'
3
3
 
4
4
  require_relative '../core-ext/arrayfy'
5
+ require_relative '../core-ext/array-explode-ranges'
6
+
7
+ using Musa::Extension::Arrayfy
8
+ using Musa::Extension::ExplodeRanges
5
9
 
6
10
  module Musa
7
11
  module MIDIVoices
@@ -5,9 +5,10 @@ module Musa
5
5
  class REPL
6
6
  @@repl_mutex = Mutex.new
7
7
 
8
- def initialize(binder, port: nil, after_eval: nil)
8
+ def initialize(binder, port: nil, after_eval: nil, logger: nil)
9
9
  port ||= 1327
10
- redirect_stderr ||= false
10
+
11
+ @logger = logger || Musa::Logger::Logger.new
11
12
 
12
13
  @block_source = nil
13
14
 
@@ -15,7 +16,7 @@ module Musa
15
16
  binder.receiver.sequencer.respond_to?(:on_error)
16
17
 
17
18
  binder.receiver.sequencer.on_error do |e|
18
- send_exception e
19
+ send_exception e, output: @connection
19
20
  end
20
21
  end
21
22
 
@@ -25,12 +26,15 @@ module Musa
25
26
  @main_thread = Thread.new do
26
27
  @server = TCPServer.new(port)
27
28
  begin
28
- while (connection = @server.accept) && @run
29
+ while (@connection = @server.accept) && @run
29
30
  @client_threads << Thread.new do
30
31
  buffer = nil
31
32
 
32
33
  begin
33
- while (line = connection.gets) && @run
34
+ while (line = @connection.gets) && @run
35
+
36
+ @logger.warn('REPL') { 'input line is nil; will close connection...' } if line.nil?
37
+
34
38
  line.chomp!
35
39
  case line
36
40
  when '#begin'
@@ -40,11 +44,14 @@ module Musa
40
44
  @block_source = buffer.string
41
45
 
42
46
  begin
43
- send_echo @block_source, output: connection
47
+ send_echo @block_source, output: @connection
44
48
  binder.eval @block_source, "(repl)", 1
45
49
 
46
50
  rescue StandardError, ScriptError => e
47
- send_exception e, output: connection
51
+ @logger.debug('REPL') { 'code execution error' }
52
+ @logger.debug('REPL') { e.full_message(highlight: true, order: :top) }
53
+
54
+ send_exception e, output: @connection
48
55
  else
49
56
  after_eval.call @block_source if after_eval
50
57
  end
@@ -53,16 +60,29 @@ module Musa
53
60
  buffer.puts line
54
61
  end
55
62
  end
63
+
56
64
  rescue IOError, Errno::ECONNRESET, Errno::EPIPE => e
57
- warn e.message
65
+ @logger.warn('REPL') { 'lost connection' }
66
+ @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
67
+
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
+ ensure
75
+ @logger.debug("REPL") { "closing connection (running #{@run})" }
76
+ @connection.close
58
77
  end
59
78
 
60
- connection.close
61
79
  end
62
80
  end
63
81
  rescue Errno::ECONNRESET, Errno::EPIPE => e
64
- warn e.message
82
+ @logger.warn('REPL') { 'connection failure while getting server port; will retry...' }
83
+ @logger.warn('REPL') { e.full_message(highlight: true, order: :top) }
65
84
  retry
85
+
66
86
  end
67
87
  end
68
88
  end
@@ -71,9 +91,10 @@ module Musa
71
91
  @run = false
72
92
 
73
93
  @main_thread.terminate
74
- @client_threads.each { |t| t.terminate }
75
-
94
+ Thread.pass
76
95
  @main_thread = nil
96
+
97
+ @client_threads.each { |t| t.terminate; Thread.pass }
77
98
  @client_threads.clear
78
99
  end
79
100
 
@@ -87,6 +108,8 @@ module Musa
87
108
 
88
109
  def send_exception(e, output:)
89
110
 
111
+ @logger.error('REPL') { e.full_message(highlight: true, order: :top) }
112
+
90
113
  send output: output, command: '//error'
91
114
 
92
115
  selected_backtrace_locations = e.backtrace_locations.select { |bt| bt.path == '(repl)' }
@@ -1,6 +1,9 @@
1
1
  require_relative '../core-ext/smart-proc-binder'
2
+ require_relative '../core-ext/inspect-nice'
2
3
  require_relative '../sequencer'
3
4
 
5
+ using Musa::Extension::InspectNice
6
+
4
7
  module Musa
5
8
  module Transport
6
9
  class Transport
@@ -15,6 +18,7 @@ module Musa
15
18
  on_start: nil,
16
19
  after_stop: nil,
17
20
  on_position_change: nil,
21
+ logger: nil,
18
22
  do_log: nil)
19
23
 
20
24
  beats_per_bar ||= 4
@@ -37,7 +41,7 @@ module Musa
37
41
 
38
42
  @do_log = do_log
39
43
 
40
- @sequencer = Sequencer::Sequencer.new beats_per_bar, ticks_per_beat, do_log: @do_log
44
+ @sequencer = Sequencer::Sequencer.new beats_per_bar, ticks_per_beat, logger: logger, do_log: @do_log
41
45
 
42
46
  @clock.on_start do
43
47
  do_on_start
@@ -78,15 +82,20 @@ module Musa
78
82
  end
79
83
 
80
84
  def change_position_to(bars: nil, beats: nil, midi_beats: nil)
81
- warn "Transport: asked to change position to #{"#{bars} bars " if bars}#{"#{beats} beats " if beats}#{"#{midi_beats} midi beats " if midi_beats}" if @do_log
85
+ logger.debug('Transport') do
86
+ "asked to change position to #{"#{bars} bars " if bars}#{"#{beats} beats " if beats}" \
87
+ "#{"#{midi_beats} midi beats " if midi_beats}"
88
+ end
82
89
 
83
90
  position = bars&.rationalize || 1r
84
91
  position += Rational(midi_beats, 4 * @sequencer.beats_per_bar) if midi_beats
85
92
  position += Rational(beats, @sequencer.beats_per_bar) if beats
86
93
 
94
+ position -= @sequencer.tick_duration
95
+
87
96
  raise ArgumentError, "undefined new position" unless position
88
97
 
89
- warn "Transport: received message position change to #{position}" if @do_log
98
+ logger.debug('Transport') { "received message position change to #{position.inspect}" }
90
99
 
91
100
  start_again_later = false
92
101
 
@@ -95,7 +104,7 @@ module Musa
95
104
  start_again_later = true
96
105
  end
97
106
 
98
- warn "Transport: setting sequencer position #{position}" if @do_log
107
+ logger.debug('Transport') { "setting sequencer position #{position.inspect}" }
99
108
 
100
109
  @sequencer.raw_at position, force_first: true do
101
110
  @on_change_position.each { |block| block.call @sequencer }
@@ -110,28 +119,32 @@ module Musa
110
119
  @clock.terminate
111
120
  end
112
121
 
122
+ def logger
123
+ @sequencer.logger
124
+ end
125
+
113
126
  private
114
127
 
115
128
  def do_before_begin
116
- warn 'Transport: doing before_begin initialization...' unless @before_begin.empty? || !@do_log
129
+ logger.debug('Transport') { 'doing before_begin initialization...' unless @before_begin.empty? }
117
130
  @before_begin.each { |block| block.call @sequencer }
118
- warn 'Transport: doing before_begin initialization... done' unless @before_begin.empty? || !@do_log
131
+ logger.debug('Transport') { 'doing before_begin initialization... done' unless @before_begin.empty? }
119
132
  end
120
133
 
121
134
  def do_on_start
122
- warn 'Transport: starting...' unless @on_start.empty? || !@do_log
135
+ logger.debug('Transport') { 'starting...' unless @on_start.empty? }
123
136
  @on_start.each { |block| block.call @sequencer }
124
- warn 'Transport: starting... done' unless @on_start.empty? || !@do_log
137
+ logger.debug('Transport') { 'starting... done' unless @on_start.empty? }
125
138
  end
126
139
 
127
140
  def do_stop
128
- warn 'Transport: stoping...' unless @after_stop.empty? || !@do_log
141
+ logger.debug('Transport') { 'stopping...' unless @after_stop.empty? }
129
142
  @after_stop.each { |block| block.call @sequencer }
130
- warn 'Transport: stoping... done' unless @after_stop.empty? || !@do_log
143
+ logger.debug('Transport') { 'stopping... done' unless @after_stop.empty? }
131
144
 
132
- warn 'Transport: resetting sequencer...' if @do_log
145
+ logger.debug('Transport') { 'resetting sequencer...' }
133
146
  @sequencer.reset
134
- warn 'Transport: resetting sequencer... done' if @do_log
147
+ logger.debug('Transport') { 'resetting sequencer... done' }
135
148
 
136
149
  do_before_begin
137
150
  @before_begin_already_done = true
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'musa-dsl'
3
- s.version = '0.21.1'
4
- s.date = '2020-10-09'
3
+ s.version = '0.21.3'
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)'
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.21.1
4
+ version: 0.21.3
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: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus