Contents page

Rules for Tools/scaletotwelve()

     char scaletotwelve(struct Clip *clip, long time, char value)

    `struct Clip  *clip'
          Clip with Key & Scale/Mode.

    `long time'
          Time of conversion.

    `char value'
          Note interval in scale.

     `scaletotwelve()' converts a note interval in the current key &
     scale/mode into a MIDI note.  For example, C octave 5 in C Major is
     35, since there are 7 notes per octave in the Major scale.
     Ssaletotwelve translates this to 60 in the chromatic, 12 notes per
     octave, MIDI scale.

     `scaletotwelve()' and its mirror operation, `twelvetoscale()',
     provide the tools to operate on musical information because they
     have an implicit understanding of the user selected key.  First,
     translate MIDI note numbers into scale intervals with
     `twelvetoscale()'.  This gives note to note intervals a
     mathematical relationship that makes sense musically.  A third is
     no longer 3 or 4 half steps, instead it is always two steps.
     Operate on the notes in this realm, then translate back to the
     chromatic MIDI scale with `scaletotwelve()'.

     `twelvetoscale()' translates a MIDI note number into a scale
     interval plus an accidental, in case the note is sharp or flat.
     The accidental is -1 for flat, 1 for sharp, and 0 for natural.  To
     keep the accidental, add it to the note after converting back with

     As with all functions that use Clips as a source for song
     parameters, if `clip' is 0, `scaletotwelve()' uses the default
     Clip, the master Song Parameters, to search for the key.  If it
     can't find a key, it assumes C Major.

     `time' is the time within the music that the conversion takes
     place.  This is neccessary because there can key signature changes.

     Here's an example piece of code that transposes a note up a third
     (2 steps in the key:)
            struct NoteEvent  *event;
  char offset;

  note->value = (*functions->twelvetoscale)
  note->value += 2;
  note->value = (*functions->scaletotwelve)
  note->value += offset

     See noteinkey(), twelvetoscale().