Top Level Namespace

Includes:
MIDI

Defined Under Namespace

Classes: MelodyToMidi

Constant Summary collapse

Q =
0.25
H =
0.5
F =
1

Instance Method Summary collapse

Instance Method Details

#clone(array) ⇒ Object



27
28
29
# File 'lib/shared_functions.rb', line 27

def clone(array)
  return [].replace(array)
end

#play_melody(m) ⇒ Object

Plays a single melody in SonicPi.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sonic_play.rb', line 18

def play_melody(m)
  in_thread do
    set_volume! 5
    if defined? mybpm
      use_bpm mybpm()
    end
    if defined? mysynth
      use_synth mysynth()
    end
  
    (0..m[0].length-1).each do |i|
      if m.length > 2
        set_volume! m[2][i]
      end
      if m[0][i] != 0
        play m[0][i]
      end
      sleep m[1][i]
    end
  end
end

#rep(value, times) ⇒ Object



23
24
25
# File 'lib/shared_functions.rb', line 23

def rep(value, times)
  return Array.new(times, value)
end

#repa(array, x) ⇒ Object

Copyright 2017 Google Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



15
16
17
18
19
20
21
# File 'lib/shared_functions.rb', line 15

def repa(array, x)
  result = []
  (1..x).each do
    result.concat(array)
  end
  return result
end

#sonic_playObject

Plays a melody in SonicPi, optionally supporting multiple sub-melodies in parallel.



42
43
44
45
46
47
48
49
50
51
# File 'lib/sonic_play.rb', line 42

def sonic_play
  melody = melody()
  if melody.respond_to?(:key)
    melody.values().each do |m|
      play_melody(m)
    end
  elsif melody.respond_to?(:length)
    play_melody(melody)
  end
end