annotate base/Pitch.h @ 519:21f86744d38e sv-v1.4

...
author Chris Cannam
date Thu, 11 Dec 2008 12:37:16 +0000
parents 0a44caddd9fe
children 451f7f3ab6e7
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@19 2
Chris@19 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@19 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@19 14 */
Chris@19 15
Chris@19 16 #ifndef _PITCH_H_
Chris@19 17 #define _PITCH_H_
Chris@19 18
Chris@19 19 #include <QString>
Chris@19 20
Chris@19 21 class Pitch
Chris@19 22 {
Chris@19 23 public:
Chris@274 24 /**
Chris@274 25 * Return the frequency at the given MIDI pitch plus centsOffset
Chris@274 26 * cents (1/100ths of a semitone). centsOffset does not have to
Chris@274 27 * be in any particular range or sign.
Chris@274 28 *
Chris@274 29 * If concertA is non-zero, use that as the reference frequency
Chris@274 30 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 31 * specified in the application preferences (default 440Hz).
Chris@274 32 */
Chris@19 33 static float getFrequencyForPitch(int midiPitch,
Chris@19 34 float centsOffset = 0,
Chris@141 35 float concertA = 0.0);
Chris@19 36
Chris@274 37 /**
Chris@274 38 * Return the nearest MIDI pitch to the given frequency.
Chris@274 39 *
Chris@274 40 * If centsOffsetReturn is non-NULL, return in *centsOffsetReturn
Chris@274 41 * the number of cents (1/100ths of a semitone) difference between
Chris@274 42 * the given frequency and that of the returned MIDI pitch. The
Chris@274 43 * cents offset will be in the range [-50,50).
Chris@274 44 *
Chris@274 45 * If concertA is non-zero, use that as the reference frequency
Chris@274 46 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 47 * specified in the application preferences (default 440Hz).
Chris@274 48 */
Chris@19 49 static int getPitchForFrequency(float frequency,
Chris@19 50 float *centsOffsetReturn = 0,
Chris@141 51 float concertA = 0.0);
Chris@19 52
Chris@274 53 /**
Chris@373 54 * Return the nearest MIDI pitch range to the given frequency
Chris@373 55 * range, that is, the difference in MIDI pitch values between the
Chris@373 56 * higher and lower frequencies.
Chris@373 57 *
Chris@373 58 * If centsOffsetReturn is non-NULL, return in *centsOffsetReturn
Chris@373 59 * the number of cents (1/100ths of a semitone) difference between
Chris@373 60 * the given frequency difference and the returned MIDI pitch
Chris@373 61 * range. The cents offset will be in the range [-50,50).
Chris@373 62 *
Chris@373 63 * If concertA is non-zero, use that as the reference frequency
Chris@373 64 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@373 65 * specified in the application preferences (default 440Hz).
Chris@373 66 */
Chris@373 67 static int getPitchForFrequencyDifference(float frequencyA,
Chris@373 68 float frequencyB,
Chris@373 69 float *centsOffsetReturn = 0,
Chris@373 70 float concertA = 0.0);
Chris@373 71
Chris@373 72 /**
Chris@274 73 * Return a string describing the given MIDI pitch, with optional
Chris@274 74 * cents offset. This consists of the note name, octave number
Chris@274 75 * (with MIDI pitch 0 having octave number -2), and optional
Chris@274 76 * cents.
Chris@274 77 *
Chris@274 78 * For example, "A#3" (A# in octave 3) or "C2-12c" (C in octave 2,
Chris@274 79 * minus 12 cents).
Chris@274 80 *
Chris@274 81 * If useFlats is true, spell notes with flats instead of sharps,
Chris@274 82 * e.g. Bb3 instead of A#3.
Chris@274 83 */
Chris@19 84 static QString getPitchLabel(int midiPitch,
Chris@26 85 float centsOffset = 0,
Chris@26 86 bool useFlats = false);
Chris@19 87
Chris@274 88 /**
Chris@274 89 * Return a string describing the nearest MIDI pitch to the given
Chris@274 90 * frequency, with cents offset.
Chris@274 91 *
Chris@274 92 * If concertA is non-zero, use that as the reference frequency
Chris@274 93 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 94 * specified in the application preferences (default 440Hz).
Chris@274 95 *
Chris@274 96 * If useFlats is true, spell notes with flats instead of sharps,
Chris@274 97 * e.g. Bb3 instead of A#3.
Chris@274 98 */
Chris@19 99 static QString getPitchLabelForFrequency(float frequency,
Chris@141 100 float concertA = 0.0,
Chris@26 101 bool useFlats = false);
Chris@274 102
Chris@274 103 /**
Chris@373 104 * Return a string describing the given pitch range in octaves,
Chris@373 105 * semitones and cents. This is in the form e.g. "1'2+4c".
Chris@373 106 */
Chris@373 107 static QString getLabelForPitchRange(int semis, float cents = 0);
Chris@373 108
Chris@373 109 /**
Chris@274 110 * Return true if the given frequency falls within the range of
Chris@274 111 * MIDI note pitches, plus or minus half a semitone. This is
Chris@274 112 * equivalent to testing whether getPitchForFrequency returns a
Chris@274 113 * pitch in the MIDI range (0 to 127 inclusive) with any cents
Chris@274 114 * offset.
Chris@274 115 *
Chris@274 116 * If concertA is non-zero, use that as the reference frequency
Chris@274 117 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 118 * specified in the application preferences (default 440Hz).
Chris@274 119 */
Chris@274 120 static bool isFrequencyInMidiRange(float frequency,
Chris@274 121 float concertA = 0.0);
Chris@19 122 };
Chris@19 123
Chris@19 124
Chris@19 125 #endif