hello,
is there also native way how to translate midi number to its note representation/name - for debugging purposes.
like print name(60) # would print C4
coz what i do now is bit overkill yet not precise
$name = [‘C’, ‘Db’, ‘D’, ‘Eb’, ‘E’, ‘F’, ‘Gb’, ‘G’, ‘Ab’, ‘A’, ‘Bb’, ‘B’].ring
print $name[value]
define :ntosym do |n|
note_info(n).to_s.split(" ")[1][1..-2].to_sym
end
define :notestosyms do |list|
list.map {|x| ntosym(x)}
end
puts notestosyms [48,68,64,53,89,43,36]
This prints out [:C3, :Ab4, :E4, :F3, :F6, :G2, :C2]
@robin.newman/@2046 - If you specifically wanted only the note name such as C4, instead of the full output of note_info, I was actually thinking of this one:
puts note_info(60).midi_string
which gives you just C4.
(Keeping in mind that using .midi_string on a Sonic Pi note object is not officially supported as part of the set of Sonic Pi user functions, it just happens to be (for the moment) one of the internal functions that Sonic Pi uses - so using it in your own code will only work so long as that doesn’t change).