class PocketMiku::Device
Public Class Methods
new(device)
click to toggle source
Args¶ ↑
- device
- String
-
MIDIデバイスファイル名
- IO,StringIO
-
出力するIOオブジェクト
Exception
¶ ↑
ファイル device が見つからず、ストリームとしても利用できない場合
# File lib/pocket_miku/device.rb, line 12 def initialize(device) @io = case device when IO,StringIO device when String open(device, 'w') else raise PocketMiku::ArgumentError, "device should give IO or String. but give `#{device.class}'" end if block_given? begin self.sing(&Proc.new) ensure @io.close end end end
Public Instance Methods
close()
click to toggle source
# File lib/pocket_miku/device.rb, line 89 def close #stop @io.close end
closed?()
click to toggle source
# File lib/pocket_miku/device.rb, line 94 def closed? @io.closed? end
play(score)
click to toggle source
score をこのデバイスで再生する
Array¶ ↑
- score
-
PocketMiku::Score
楽譜情報
Exception
¶ ↑
packetの中に、1byte(0..255)に収まらない数値がある場合
# File lib/pocket_miku/device.rb, line 51 def play(score) score.map{|note|[note, note.to_s.freeze]}.each do |note, packet| case note when RestNote sleep Rational(60.to_f, score.tempo) * Rational(note.length.to_f, Note4) when Note @io << packet @io.flush sleep Rational(60.to_f, score.tempo) * Rational(note.length.to_f, Note4) stop 0, note.key @io.flush end end end
Also aliased as: +@
send(packet)
click to toggle source
sing(score=nil)
click to toggle source
ブロックをこのインスタンスのコンテキストで実行してから、ポケットミクで再生する
Array¶ ↑
- score
-
PocketMiku::Score
楽譜情報
Return¶ ↑
ブロックの評価結果
# File lib/pocket_miku/device.rb, line 84 def sing(score=nil) score = PocketMiku::Score.new(&Proc.new) if block_given? play score end