Class: PocketMiku::Score

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pocket_miku/score.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScore

Returns a new instance of Score.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pocket_miku/score.rb', line 9

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/pocket_miku/score.rb', line 86

def method_missing(method, *args)
  case method
  when -> _ {CharTable.include? _}
    generate_note method, *args
  else
    super
  end
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



7
8
9
# File 'lib/pocket_miku/score.rb', line 7

def default
  @default
end

Instance Method Details

#add(note) ⇒ Object

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

Args

note

PocketMiku::Note

Return

self



55
56
57
58
# File 'lib/pocket_miku/score.rb', line 55

def add(note)
  @playlist << note
  self
end

#eachObject



28
29
30
# File 'lib/pocket_miku/score.rb', line 28

def each
  @playlist.each(&Proc.new)
end

#generate_note(sound, options = nil) ⇒ Object

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

Args

sound

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

options

以下のいずれか

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

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

Return

self



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pocket_miku/score.rb', line 69

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

#tempo(new = nil) ⇒ Object

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

Args

new
  • nil(指定なし)

    現在のテンポを返す

  • Integer

    テンポをこの値に設定

Return

現在のテンポ



39
40
41
42
43
44
45
46
47
48
# File 'lib/pocket_miku/score.rb', line 39

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_aObject



24
25
26
# File 'lib/pocket_miku/score.rb', line 24

def to_a
  @playlist.dup
end

#(length) ⇒ Object



82
83
84
# File 'lib/pocket_miku/score.rb', line 82

def (length)
  add PocketMiku::RestNote.new(length)
end