mmplayer 0.0.8 → 0.0.9

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
  SHA1:
3
- metadata.gz: 14f79ab624c5547f520491380f1fd012f649daad
4
- data.tar.gz: a2387b2bdd5e1787dbb3a5913cd9518633a69b58
3
+ metadata.gz: 3f14f476af4864cb82c33c1b2096380155d7cc66
4
+ data.tar.gz: 72cadd99a43d83aa6d326b95e3f07ad40ac26066
5
5
  SHA512:
6
- metadata.gz: 10967965c48de9cb4053ce32b41b907b18e1ecc54b33e23f4c9cd63f8d1ca6c7f991ed02fc2694fd5bbd42774874f6eb9a8cafdfcf77b8196a3e9e92f345d57f
7
- data.tar.gz: 1c21b76e1044de417220d6706bba6b1300f11d90da9e437ef0a14ecaa1cae550738298b3f679414acfd32946fda2444be6bfb597ca2d897ed717c0e7b5d8deb9
6
+ metadata.gz: d07078cd8a53754fdbc07b82e0ee29966e86adfc14beadd2338e6a53470b770db656202111d320127a18c7003435fa4d4effba4f8da7542e6615e7a739b31de7
7
+ data.tar.gz: 9ba11777b930ccfc08c0c189e6cf5dee7081f8cdfc7ac86bb4113a56b1c2a5961b154a636f7ad2fefcf75a844c1e71b275d27af3d5f35e1fa1968567705c3270
data/lib/mmplayer.rb CHANGED
@@ -9,6 +9,7 @@ require "forwardable"
9
9
  require "midi-eye"
10
10
  require "mplayer-ruby"
11
11
  require "scale"
12
+ require "timeout"
12
13
  require "unimidi"
13
14
 
14
15
  # modules
@@ -16,13 +17,14 @@ require "mmplayer/helper/numbers"
16
17
  require "mmplayer/instructions"
17
18
  require "mmplayer/midi"
18
19
  require "mmplayer/player"
20
+ require "mmplayer/thread"
19
21
 
20
22
  # classes
21
23
  require "mmplayer/context"
22
24
 
23
25
  module MMPlayer
24
26
 
25
- VERSION = "0.0.8"
27
+ VERSION = "0.0.9"
26
28
 
27
29
  # Shortcut to Context constructor
28
30
  def self.new(*args, &block)
@@ -9,14 +9,14 @@ module MMPlayer
9
9
 
10
10
  attr_reader :midi, :player
11
11
 
12
- # @param [UniMIDI::Input] midi_input
12
+ # @param [UniMIDI::Input, Array<UniMIDI::Input>] midi_input
13
13
  # @param [Hash] options
14
14
  # @option options [String] :mplayer_flags The command-line flags to invoke MPlayer with
15
15
  # @option options [Fixnum] :receive_channel (also: :rx_channel) A MIDI channel to subscribe to. By default, responds to all
16
16
  # @yield
17
17
  def initialize(midi_input, options = {}, &block)
18
- @midi = MIDI::Wrapper.new(midi_input, :receive_channel => options[:receive_channel] || options[:rx_channel])
19
- @player = Player::Wrapper.new(:flags => options[:mplayer_flags])
18
+ @midi = MIDI.new(midi_input, :receive_channel => options[:receive_channel] || options[:rx_channel])
19
+ @player = Player.new(:flags => options[:mplayer_flags])
20
20
  instance_eval(&block) if block_given?
21
21
  end
22
22
 
@@ -37,6 +37,7 @@ module MMPlayer
37
37
  def stop
38
38
  @midi.stop
39
39
  @player.quit
40
+ @playback_thread.kill
40
41
  true
41
42
  end
42
43
 
@@ -44,18 +45,12 @@ module MMPlayer
44
45
 
45
46
  # Main playback loop
46
47
  def playback_loop
47
- thread = Thread.new do
48
- begin
49
- until @player.active?
50
- sleep(0.1)
51
- end
52
- @player.playback_loop
53
- rescue Exception => exception
54
- Thread.main.raise(exception)
48
+ ::MMPlayer::Thread.new(:timeout => false) do
49
+ until @player.active?
50
+ sleep(0.1)
55
51
  end
52
+ @player.playback_loop
56
53
  end
57
- thread.abort_on_exception = true
58
- thread
59
54
  end
60
55
 
61
56
  end
data/lib/mmplayer/midi.rb CHANGED
@@ -4,6 +4,11 @@ require "mmplayer/midi/wrapper"
4
4
  module MMPlayer
5
5
 
6
6
  module MIDI
7
+
8
+ def self.new(*args)
9
+ ::MMPlayer::MIDI::Wrapper.new(*args)
10
+ end
11
+
7
12
  end
8
13
 
9
14
  end
@@ -1,12 +1,13 @@
1
1
  module MMPlayer
2
2
 
3
3
  module MIDI
4
+
4
5
  # Wrapper for MIDI functionality
5
6
  class Wrapper
6
7
 
7
- attr_reader :channel, :config, :listener, :message_handler
8
+ attr_reader :channel, :listener, :message_handler
8
9
 
9
- # @param [UniMIDI::Input] input
10
+ # @param [UniMIDI::Input, Array<UniMIDI::Input>] input
10
11
  # @param [Hash] options
11
12
  # @option options [Fixnum] :receive_channel A MIDI channel to subscribe to. By default, responds to all
12
13
  def initialize(input, options = {})
@@ -6,6 +6,11 @@ require "mmplayer/player/wrapper"
6
6
  module MMPlayer
7
7
 
8
8
  module Player
9
+
10
+ def self.new(*args)
11
+ ::MMPlayer::Player::Wrapper.new(*args)
12
+ end
13
+
9
14
  end
10
15
 
11
16
  end
@@ -26,15 +26,10 @@ module MMPlayer
26
26
  # @return [MPlayer::Slave]
27
27
  def ensure_invoked(file, state)
28
28
  if @player.nil? && @thread.nil?
29
- @thread = Thread.new do
30
- begin
31
- @player = MPlayer::Slave.new(file, :options => @flags)
32
- state.handle_start
33
- rescue Exception => exception
34
- Thread.main.raise(exception)
35
- end
29
+ @thread = ::MMPlayer::Thread.new(:timeout => false) do
30
+ @player = MPlayer::Slave.new(file, :options => @flags)
31
+ state.handle_start
36
32
  end
37
- @thread.abort_on_exception
38
33
  end
39
34
  @player
40
35
  end
@@ -17,14 +17,7 @@ module MMPlayer
17
17
  timestamp = Time.now.to_f
18
18
  # Throttled messages are disregarded
19
19
  if @messages.empty? || !throttle?(timestamp, @messages.last[:timestamp])
20
- thread = Thread.new do
21
- begin
22
- yield
23
- rescue Exception => exception
24
- Thread.main.raise(exception)
25
- end
26
- end
27
- thread.abort_on_exception = true
20
+ thread = ::MMPlayer::Thread.new(&block)
28
21
  record_message(thread, timestamp)
29
22
  end
30
23
  end
@@ -25,7 +25,7 @@ module MMPlayer
25
25
  if @player.nil?
26
26
  false
27
27
  else
28
- @threads << with_thread do
28
+ @threads << ::MMPlayer::Thread.new(:timeout => 2) do
29
29
  @player.load_file(file)
30
30
  handle_start
31
31
  end
@@ -52,7 +52,7 @@ module MMPlayer
52
52
  def playback_loop
53
53
  loop do
54
54
  if handle_progress?
55
- @threads << with_thread { handle_progress }
55
+ @threads << ::MMPlayer::Thread.new { handle_progress }
56
56
  end
57
57
  handle_eof if handle_eof?
58
58
  sleep(0.05)
@@ -190,19 +190,6 @@ module MMPlayer
190
190
  result.strip.to_f
191
191
  end
192
192
 
193
- # Call the given block within a new thread
194
- def with_thread(&block)
195
- thread = Thread.new do
196
- begin
197
- yield
198
- rescue Exception => exception
199
- Thread.main.raise(exception)
200
- end
201
- end
202
- thread.abort_on_exception = true
203
- thread
204
- end
205
-
206
193
  end
207
194
 
208
195
  end
@@ -0,0 +1,28 @@
1
+ module MMPlayer
2
+
3
+ module Thread
4
+
5
+ extend self
6
+
7
+ def new(options = {}, &block)
8
+ thread = ::Thread.new do
9
+ begin
10
+ if options[:timeout] === false
11
+ yield
12
+ else
13
+ duration = options[:timeout] || 1
14
+ Timeout::timeout(duration) { yield }
15
+ end
16
+ rescue Timeout::Error
17
+ ::Thread.current.kill
18
+ rescue Exception => exception
19
+ ::Thread.main.raise(exception)
20
+ end
21
+ end
22
+ thread.abort_on_exception = true
23
+ thread
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -1,8 +1,8 @@
1
1
  require "helper"
2
2
 
3
- class MMPlayer::MIDITest < Minitest::Test
3
+ class MMPlayer::MIDI::WrapperTest < Minitest::Test
4
4
 
5
- context "MIDI" do
5
+ context "Wrapper" do
6
6
 
7
7
  setup do
8
8
  @input = Object.new
@@ -1,8 +1,8 @@
1
1
  require "helper"
2
2
 
3
- class MMPlayer::PlayerTest < Minitest::Test
3
+ class MMPlayer::Player::WrapperTest < Minitest::Test
4
4
 
5
- context "Player" do
5
+ context "Wrapper" do
6
6
 
7
7
  setup do
8
8
  @player = MMPlayer::Player::Wrapper.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmplayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -213,14 +213,15 @@ files:
213
213
  - lib/mmplayer/player/messenger.rb
214
214
  - lib/mmplayer/player/state.rb
215
215
  - lib/mmplayer/player/wrapper.rb
216
+ - lib/mmplayer/thread.rb
216
217
  - test/context_test.rb
217
218
  - test/helper.rb
218
219
  - test/helper/numbers_test.rb
219
220
  - test/instructions/midi_test.rb
220
221
  - test/instructions/player_test.rb
221
222
  - test/midi/message_handler_test.rb
222
- - test/midi_test.rb
223
- - test/player_test.rb
223
+ - test/midi/wrapper_test.rb
224
+ - test/player/wrapper_test.rb
224
225
  homepage: http://github.com/arirusso/mmplayer
225
226
  licenses:
226
227
  - Apache 2.0