annotate base/Pitch.h @ 326:bb6e4c46e202

* Fix availability of alignment button and relative align/solo button state
author Chris Cannam
date Thu, 01 Nov 2007 16:02:01 +0000
parents e412f65884ee
children 0a44caddd9fe
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@274 54 * Return a string describing the given MIDI pitch, with optional
Chris@274 55 * cents offset. This consists of the note name, octave number
Chris@274 56 * (with MIDI pitch 0 having octave number -2), and optional
Chris@274 57 * cents.
Chris@274 58 *
Chris@274 59 * For example, "A#3" (A# in octave 3) or "C2-12c" (C in octave 2,
Chris@274 60 * minus 12 cents).
Chris@274 61 *
Chris@274 62 * If useFlats is true, spell notes with flats instead of sharps,
Chris@274 63 * e.g. Bb3 instead of A#3.
Chris@274 64 */
Chris@19 65 static QString getPitchLabel(int midiPitch,
Chris@26 66 float centsOffset = 0,
Chris@26 67 bool useFlats = false);
Chris@19 68
Chris@274 69 /**
Chris@274 70 * Return a string describing the nearest MIDI pitch to the given
Chris@274 71 * frequency, with cents offset.
Chris@274 72 *
Chris@274 73 * If concertA is non-zero, use that as the reference frequency
Chris@274 74 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 75 * specified in the application preferences (default 440Hz).
Chris@274 76 *
Chris@274 77 * If useFlats is true, spell notes with flats instead of sharps,
Chris@274 78 * e.g. Bb3 instead of A#3.
Chris@274 79 */
Chris@19 80 static QString getPitchLabelForFrequency(float frequency,
Chris@141 81 float concertA = 0.0,
Chris@26 82 bool useFlats = false);
Chris@274 83
Chris@274 84 /**
Chris@274 85 * Return true if the given frequency falls within the range of
Chris@274 86 * MIDI note pitches, plus or minus half a semitone. This is
Chris@274 87 * equivalent to testing whether getPitchForFrequency returns a
Chris@274 88 * pitch in the MIDI range (0 to 127 inclusive) with any cents
Chris@274 89 * offset.
Chris@274 90 *
Chris@274 91 * If concertA is non-zero, use that as the reference frequency
Chris@274 92 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 93 * specified in the application preferences (default 440Hz).
Chris@274 94 */
Chris@274 95 static bool isFrequencyInMidiRange(float frequency,
Chris@274 96 float concertA = 0.0);
Chris@19 97 };
Chris@19 98
Chris@19 99
Chris@19 100 #endif