annotate base/Pitch.h @ 997:2104ea2204d2

Separate out stdout ability (not all writers that support one-file will necessarily want to support it, e.g. for binary formats)
author Chris Cannam
date Mon, 13 Oct 2014 10:56:16 +0100
parents 451f7f3ab6e7
children 1f62a890da58
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@892 74 * cents offset. This consists of the note name, octave number,
Chris@892 75 * and optional cents. The octave numbering system is based on the
Chris@892 76 * application preferences (default is C4 = middle C, though in
Chris@892 77 * previous SV releases that was C3).
Chris@274 78 *
Chris@274 79 * For example, "A#3" (A# in octave 3) or "C2-12c" (C in octave 2,
Chris@274 80 * minus 12 cents).
Chris@274 81 *
Chris@274 82 * If useFlats is true, spell notes with flats instead of sharps,
Chris@274 83 * e.g. Bb3 instead of A#3.
Chris@274 84 */
Chris@19 85 static QString getPitchLabel(int midiPitch,
Chris@26 86 float centsOffset = 0,
Chris@26 87 bool useFlats = false);
Chris@19 88
Chris@274 89 /**
Chris@274 90 * Return a string describing the nearest MIDI pitch to the given
Chris@274 91 * frequency, with cents offset.
Chris@274 92 *
Chris@274 93 * If concertA is non-zero, use that as the reference frequency
Chris@274 94 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 95 * specified in the application preferences (default 440Hz).
Chris@274 96 *
Chris@274 97 * If useFlats is true, spell notes with flats instead of sharps,
Chris@274 98 * e.g. Bb3 instead of A#3.
Chris@274 99 */
Chris@19 100 static QString getPitchLabelForFrequency(float frequency,
Chris@141 101 float concertA = 0.0,
Chris@26 102 bool useFlats = false);
Chris@274 103
Chris@274 104 /**
Chris@373 105 * Return a string describing the given pitch range in octaves,
Chris@373 106 * semitones and cents. This is in the form e.g. "1'2+4c".
Chris@373 107 */
Chris@373 108 static QString getLabelForPitchRange(int semis, float cents = 0);
Chris@373 109
Chris@373 110 /**
Chris@274 111 * Return true if the given frequency falls within the range of
Chris@274 112 * MIDI note pitches, plus or minus half a semitone. This is
Chris@274 113 * equivalent to testing whether getPitchForFrequency returns a
Chris@274 114 * pitch in the MIDI range (0 to 127 inclusive) with any cents
Chris@274 115 * offset.
Chris@274 116 *
Chris@274 117 * If concertA is non-zero, use that as the reference frequency
Chris@274 118 * for the A at MIDI pitch 69; otherwise use the tuning frequency
Chris@274 119 * specified in the application preferences (default 440Hz).
Chris@274 120 */
Chris@274 121 static bool isFrequencyInMidiRange(float frequency,
Chris@274 122 float concertA = 0.0);
Chris@19 123 };
Chris@19 124
Chris@19 125
Chris@19 126 #endif