topical media & game development

talk show tell print

actionscript-omr-lib-Pitch.ax

actionscript-omr-lib-Pitch.ax [swf] flex


  package 
  {
          public class @ax-actionscript-omr-lib-Pitch
          {
                  private var octave:int;
                  private var tone:int;
                  public function @ax-actionscript-omr-lib-Pitch(octave:int, tone:int)
                  {
                          
                          this.octave = octave;
                          if (octave==4){
                                  //treble clef
                                  //0-23, 5 = c5, 4 =a4
                                  //0 is F6
                                  
                                  
                          }
                          
                          
                          this.tone=tone;
                          
                  }
                  
                  
                  public function getnoteName():String{
  
F6 = 23 //done with switch, not very elegant but it does the job, tables of 12 are just as bad switch (tone) { case 23: return "F6" break; case 22: return "E6" break; case 21: return "DS6" break; case 20: return "D6" break; case 19: return "CS6" break; case 18: return "C6" break; case 17: return "B5" break; case 16: return "AS5" break; case 15: return "A5" break; case 14: return "GS5" break; case 13: return "G5" break; case 12: return "FS5" break; case 11: return "F5" break; case 10: return "E5" break; case 9: return "DS5" break; case 8: return "D5" break; case 7: return "CS5" break; case 6: return "C5" break; case 5: return "B4" break; case 4: return "AS4" break; case 3: return "A4" break; case 2: return "GS4" break; case 1: return "G4" break; case 0: return "AS4" break; default: return ""; trace ( " no case tested true " ) }

                  }
                  public function getFrequency():Number{
                          //returns frequency in Hertz
                          //notes separated by facor 2^12
                          //octave value is the value used for clef indication
                          //Go from 0 = octave+2
                          //F6 = 1396.9hz,  23 in 0-23 scale 
                          var f6:Number = 1396.9;
                          var noteFrequency:Number = f6 * (2^(-tone/12));
                          
                          return noteFrequency;
                  }
  
          }
  }


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.