Module: Rusholme::Handler

Defined in:
lib/rusholme/handler.rb

Instance Method Summary collapse

Instance Method Details

#convert_note_to_freq(note_number) ⇒ Object



6
7
8
# File 'lib/rusholme/handler.rb', line 6

def convert_note_to_freq(note_number)
  (440 * 2 ** ((note_number - 69)/12.0)).round(1)
end

#receive_data(buffer) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rusholme/handler.rb', line 10

def receive_data(buffer)
  # puts ">>> #{convert_note_to_freq(buffer.ord)}"
  begin
    osc_client = OSCClient.new
  rescue SocketError => e
    puts e.message
    retry
  end
  # osc_client.send("/message", convert_note_to_freq(buffer.ord).to_s)
  note = Noone::KEYBOARD_TABLE.fetch(buffer) { |_k| nil }
  return unless note
  puts "#{note} : #{Noone::NOTE_TABLE[note]}"
  osc_client.send("/note", Noone::NOTE_TABLE[note])
end