Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_comm.rb,
lib/commands/sound.rb

Instance Method Summary collapse

Instance Method Details

#from_hex_strObject



43
44
45
46
47
48
# File 'lib/nxt_comm.rb', line 43

def from_hex_str
  data = self.split(' ')
  str = ""
  data.each{|h| eval "str += '%c' % #{h}"}
  str
end

#to_freqObject

converts a note string to equiv frequency in Hz TODO need to get a better range…



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/commands/sound.rb', line 72

def to_freq
  case self.downcase
    when "c"
      523
    when "c#"
      554
    when "d"
      587
    when "d#"
      622
    when "e"
      659
    when "f"
      698
    when "f#"
      740
    when "g"
      784
    when "g#"
      830
    when "a"
      880
    when "a#"
      923
    when "b"
      988
    else
      raise "Unknown Note: #{self}"
  end
end

#to_hex_strObject



37
38
39
40
41
# File 'lib/nxt_comm.rb', line 37

def to_hex_str
  str = ""
  self.each_byte {|b| str << '0x%02x ' % b}
  str
end