class PocketMiku::Score

Attributes

default[R]

Public Class Methods

new() click to toggle source
# File lib/pocket_miku/score.rb, line 8
def initialize
  @default = PocketMiku::Note.new(sound: 0,
                                  key: 60,
                                  velocity: 100,
                                  pitchbend: 0,
                                  length: QuarterNote)
  @playlist = []
  @tempo = 120
  if block_given?
    record(&Proc.new)
  end
end

Public Instance Methods

add(note) click to toggle source

PocketMiku::Note を末尾に追加する

Args

note

PocketMiku::Note

Return

self

# File lib/pocket_miku/score.rb, line 54
def add(note)
  @playlist << note
  self
end
each() click to toggle source
# File lib/pocket_miku/score.rb, line 27
def each
  @playlist.each(&Proc.new)
end
generate_note(sound, options=nil) click to toggle source

Note を作成して、再生キューの末尾に追加する

Args

sound

Symbol|Integer 発音する文字テーブルの文字(Symbol)か番号(Integer)

options

以下のいずれか

- Integer :: 音の高さ(key)
- Hash :: PocketMiku::Noteの第一引数

設定されたなかった Note のオプションは、 default の値が使われる

Return

self

# File lib/pocket_miku/score.rb, line 68
def generate_note(sound, options=nil)
  add case options
      when NilClass
        PocketMiku::Note.new default.to_h.merge sound: sound
      when Integer
        PocketMiku::Note.new default.to_h.merge sound: sound, key: options
      when Hash, -> _ {_.respond_to? :to_h}
        PocketMiku::Note.new default.to_h.merge(options).merge sound: sound
      else
        raise ArgumentError, "options must nil, Integer, or Hash. but given `#{options.class}'"
      end
end
method_missing(method, *args) click to toggle source
Calls superclass method
# File lib/pocket_miku/score.rb, line 85
def method_missing(method, *args)
  case method
  when -> _ {CharTable.include? _}
    generate_note method, *args
  else
    super
  end
end
tempo(new=nil) click to toggle source

再生速度を取得/設定する。テンポの値は、1分間に再生する四分音符の数

Args

new
  • nil(指定なし)

    現在のテンポを返す

  • Integer

    テンポをこの値に設定

Return

現在のテンポ

# File lib/pocket_miku/score.rb, line 38
def tempo(new=nil)
  case new
  when nil
    @tempo
  when Integer
    @tempo = new
  else
    raise ArgumentError, "new mush nil or Integer but give `#{new.class}'"
  end
end
to_a() click to toggle source
# File lib/pocket_miku/score.rb, line 23
def to_a
  @playlist.dup
end
(length) click to toggle source
# File lib/pocket_miku/score.rb, line 81
def (length)
  add PocketMiku::RestNote.new(length)
end