Music notes - Octave - Code Explanation

Sharky Forums


Results 1 to 5 of 5

Thread: Music notes - Octave - Code Explanation

Threaded View

  1. #5
    Invisible Modfish
    Join Date
    Dec 2000
    Location
    Georgia
    Posts
    2,690
    Quote Originally Posted by shinju View Post
    Sorry for the late response.
    Actually a understand the music theory (I think) mi problem is with the coding:
    I have this mathematical operation ((Oct+1) *12 ) + note) that gets the MIDI values where the octave is from -1 to 9 and the note is 1-12 ( if I remember correctly) however I am not sure how to asing this values for the code to recognize it. For example:

    for C# the value of the note will be 1 for the octave 2 so the MIDI value is: 37
    I think you may be referring to a piece of the code you're looking at that you haven't posted. C# in octave 2 has a MIDI value of 25 typically. I'm guessing that whatever you're looking at has assigned the octaves to an array and you're seeing 2 as the octave index so it's actually octave 3 in most charts I hit on a quick google.

    Somewhere near that chunk of code you're looking at you should find another array or hash or whatever that ties each of the notes to a value with C# being 1 and each note after it incrementing by 1 so D is 2, D# is 3, and so on. I'm pretty sure you'll find the range for notes is 0-11 as well since that's the only way the formula will work for C on octave 0

    It's just an quick and easy way to figure out your midi value given an octave and note.

    This also tells us that the original code is probably giving an off-by-one error when printing out the octave. It would be make more sense and be slightly more readable to label them 0 to 10 and it fits better with the MIDI spec since apparently MIDI 60 is defined as middle C and everything else is relative, but it seems to be arbitrary.
    Last edited by Vindir; 10-17-2013 at 11:24 PM.
    Insert ancient Sharky sig here
    [
    Prince Vindir of the OC Crusaders
    Holding Boundaries and Breaking Barriers

    ]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •