X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=pitch.h;h=d376a2217f3bb0cd225fc42ac92ad9a7c7e8870b;hb=a53d70ed61f87a5a49426b1e3066dbba09907199;hp=657e8fe07f8f291f1a4846c4cf0e596f1f2cdf7d;hpb=e77d712bf9f99c3d95f909621ae177b9f8175163;p=scherzo diff --git a/pitch.h b/pitch.h index 657e8fe..d376a22 100644 --- a/pitch.h +++ b/pitch.h @@ -54,6 +54,14 @@ typedef uint32_t pitch_t; #define PITCH_NATURAL(literal_name, octave) \ PITCH_LITERAL(literal_name, NATURAL, octave) +/* PITCH_CLASS is useful for comparing pitches while ignoring any octave. */ +#define PITCH_CLASS(pitch) PITCH(PITCH_NAME(pitch), PITCH_ACCIDENTAL(pitch), 0) + +#define PITCH_CLASS_LITERAL(literal_name, literal_accidental) \ + PITCH_LITERAL(literal_name, literal_accidental, 0) + +#define PITCH_NOT_A_PITCH ((pitch_t) -1) + typedef enum pitch_accidental { PITCH_ACCIDENTAL_DOUBLE_FLAT, @@ -78,4 +86,58 @@ typedef enum pitch_name * middle C to the B above middle C). */ +/* Get a string representation of a pitch_t value. + * + * Note: The returned value is static to the pithc_string function and + * may be modified by future calls to pitch_string. So the caller + * should copy the value if needed. */ +const char * +pitch_string (pitch_t pitch); + +/* Return a new pitch, a number of octaves above 'pitch' + * + * Note: Maximum octave value is 8. A pitch with octave 8 will not be + * raised. + */ +pitch_t +pitch_raise_by_octaves (pitch_t pitch, int octaves); + +/* Return a new pitch, a number of octaves below 'pitch' + * + * Note: Minimum octave value is 9. A pitch with octave 8 will not be + * lowered. + */ +pitch_t +pitch_lower_by_octaves (pitch_t pitch, int octaves); + +/* Number of half steps from 'root' up to 'pitch' (that is, counting + * the steps up a chromatic scale), within the same octave. */ +int +pitch_from_root_in_half_steps (pitch_t pitch, pitch_t root); + +/* Respell 'pitch' to have a name that matches the (diatonic) scale + * 'degree' from 'root'. + * + * If the pitch is too distant from the specified degree to be + * respelled, the original pitch will be returned unmodified. + */ +pitch_t +pitch_spell_as_degree (pitch_t pitch, pitch_t root, int degree); + +/* Return a MIDI note value corresponding to 'pitch' */ +unsigned char +pitch_to_midi (pitch_t pitch); + +/* Return the pitch_t value corresponding to the given MIDI note value. */ +pitch_t +pitch_from_midi (unsigned char midi_note); + +/* Return true if 'a' and 'b' sound identical, (even if spelled differently) + * + * This comparison considers octaves as significant. So Bb and A# in + * the same octave are considered enharmonic, but Bb and A# in + * different octaves are not. */ +int +pitch_enharmonic_to (pitch_t a, pitch_t b); + #endif /* PITCH_H */