Forums

Human Pitch to Midi Pitch (uncommenting a comment)

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Human Pitch to Midi Pitch (uncommenting a comment)

Postby DelphiGuy » Mon Aug 06, 2012 12:47 pm

I need to be able to use musical pitch names to represent midi pitch numbers.

Here's a couple of typical examples:

Middle C is typically referred to in shorthand as "C4" (C from the 4th octave on a piano keyboard) and the usual corresponding MIDI pitch representation is the integer 60.

Similarly, human "C#4" is the same-sounding pitch as Midi "61".

In my code, it would be quite convenient to use the shorthand "C#4" interchangeably with the integer 61. Without creating a table of strings and an obligatory function to convert back and forth, is there a simple way to overcome "#" being interpreted as a Cobra comment?

No doubt I'm overthinking this trivial matter and should just have human "C#4" equal Midi "61" equal Cobra "Cs4", which would easily permit constants or enums to be set up. But is there a better way that allows use of the # symbol?
DelphiGuy
 
Posts: 116

Re: Human Pitch to Midi Pitch (uncommenting a comment)

Postby nerdzero » Mon Aug 06, 2012 1:39 pm

You mean use the '#' character in a variable or constant name? I don't think it's possible.
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Human Pitch to Midi Pitch (uncommenting a comment)

Postby Charles » Wed Aug 08, 2012 11:52 am

The # symbol is used for single line comments and cannot be used in identifiers. So you need a different approach like you mentioned (Cs4) or you need to use strings like:
trace pitches['C#4']

But when using strings, you won't get any compile-time error checking on the name. On the other hand, you could provide conveniences like making the name insensitive to case and spaces, or deriving the midi pitch with a computation against the string contents if there is such a formula.

Whichever works best for you.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 118 guests