Class: MidiScales

Inherits:
ArduinoSketch show all
Defined in:
lib/examples/midi_scales.rb

Instance Attribute Summary

Attributes inherited from ArduinoSketch

#pins

Instance Method Summary collapse

Methods inherited from ArduinoSketch

#add, add_to_setup, #array, #assembler, #comment_box, #compose_setup, #define, #delay, #digitalWrite, #formatted_print, #initialize, #input_pin, #input_pins, output_pin, #output_pin, post_process_ruby_to_c_methods, pre_process, #serial_begin

Methods included from ExternalVariableProcessing

#c_type, #check_variable_type, #post_process_arrays, #post_process_vars, #pre_process_vars, #process_external_vars, #translate_variables

Constructor Details

This class inherits a constructor from ArduinoSketch

Instance Method Details

#change_channelsObject



51
52
53
54
55
# File 'lib/examples/midi_scales.rb', line 51

def change_channels 
  0.upto(6) do |channel| 
    play channel, 50, 100
  end
end

#change_pressureObject



45
46
47
48
49
# File 'lib/examples/midi_scales.rb', line 45

def change_pressure
  110.upto(127) do |pressure| 
     play 0, 45, pressure
  end
end

#change_toneObject



39
40
41
42
43
# File 'lib/examples/midi_scales.rb', line 39

def change_tone 
  110.upto(127) do |note|
    play 0, note, 127
  end
end

#loopObject



30
31
32
33
34
35
36
37
# File 'lib/examples/midi_scales.rb', line 30

def loop
  change_tone if button_one.read_input
  change_pressure if button_two.read_input
  change_channels if button_three.read_input
  read_sensor_one
  read_sensor_two
  read_sensor_three
end

#play(chan, note, pressure) ⇒ Object



83
84
85
86
87
88
# File 'lib/examples/midi_scales.rb', line 83

def play(chan, note, pressure)
  f = 1 + chan + note + pressure # hack to coerce args to int
  note_on(chan, note, pressure)
  delay 100 # adjust to need
  note_off(chan, note, 0)
end

#play_with_no_delay(chan, note, pressure) ⇒ Object

note is not turned off



90
91
92
93
# File 'lib/examples/midi_scales.rb', line 90

def play_with_no_delay(chan, note, pressure) # note is not turned off
  f = 1 + chan + note + pressure # hack to coerce args to int
  note_on(chan, note, pressure)
end

#pre_play(current_note, last_note, channel) ⇒ Object

warning, don’t use last as a parameter…



75
76
77
78
79
80
81
# File 'lib/examples/midi_scales.rb', line 75

def pre_play(current_note, last_note, channel) # warning, don't use last as a parameter...
  n = 1 + channel
  unless current_note == last_note
    @note = ((current_note /16) + 40)
    play_with_no_delay( channel, @note, 100 )
  end
end

#read_sensor_oneObject



57
58
59
60
61
# File 'lib/examples/midi_scales.rb', line 57

def read_sensor_one
  @current_note = sensor_one.soft_lock
  pre_play(@current_note, @last_note_one, 13)
  @last_note_one = @current_note
end

#read_sensor_threeObject



69
70
71
72
73
# File 'lib/examples/midi_scales.rb', line 69

def read_sensor_three
  @current_note = sensor_three.soft_lock
  pre_play(@current_note, @last_note_three, 15)
  @last_note_three = @current_note
end

#read_sensor_twoObject



63
64
65
66
67
# File 'lib/examples/midi_scales.rb', line 63

def read_sensor_two
  @current_note = sensor_two.soft_lock
  pre_play(@current_note, @last_note_two, 14)
  @last_note_two = @current_note
end

#setupObject



26
27
28
# File 'lib/examples/midi_scales.rb', line 26

def setup
  delay 3000
end