Pitch.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_PITCH_H
17 #define SV_PITCH_H
18 
19 #include <QString>
20 
21 class Pitch
22 {
23 public:
33  static double getFrequencyForPitch(int midiPitch,
34  double centsOffset = 0,
35  double concertA = 0.0);
36 
49  static int getPitchForFrequency(double frequency,
50  double *centsOffsetReturn = 0,
51  double concertA = 0.0);
52 
57  static int getPitchForFrequency(double frequency,
58  float *centsOffsetReturn,
59  double concertA = 0.0) {
60  double c;
61  int p = getPitchForFrequency(frequency, &c, concertA);
62  if (centsOffsetReturn) *centsOffsetReturn = float(c);
63  return p;
64  }
65 
80  static int getPitchForFrequencyDifference(double frequencyA,
81  double frequencyB,
82  double *centsOffsetReturn = 0,
83  double concertA = 0.0);
84 
89  static int getPitchForFrequencyDifference(double frequencyA,
90  double frequencyB,
91  float *centsOffsetReturn,
92  double concertA = 0.0) {
93  double c;
94  int p = getPitchForFrequencyDifference(frequencyA, frequencyB,
95  &c, concertA);
96  if (centsOffsetReturn) *centsOffsetReturn = float(c);
97  return p;
98  }
99 
106  static int getPitchForNoteAndOctave(int note, int octave);
107 
114  static void getNoteAndOctaveForPitch(int midiPitch, int &note, int &octave);
115 
129  static QString getPitchLabel(int midiPitch,
130  double centsOffset = 0,
131  bool useFlats = false);
132 
144  static QString getPitchLabelForFrequency(double frequency,
145  double concertA = 0.0,
146  bool useFlats = false);
147 
152  static QString getLabelForPitchRange(int semis, double cents = 0);
153 
165  static bool isFrequencyInMidiRange(double frequency,
166  double concertA = 0.0);
167 };
168 
169 
170 #endif
static int getPitchForNoteAndOctave(int note, int octave)
Return the MIDI pitch for the given note number (0-12 where 0 is C) and octave number.
Definition: Pitch.cpp:104
static double getFrequencyForPitch(int midiPitch, double centsOffset=0, double concertA=0.0)
Return the frequency at the given MIDI pitch plus centsOffset cents (1/100ths of a semitone)...
Definition: Pitch.cpp:23
static QString getLabelForPitchRange(int semis, double cents=0)
Return a string describing the given pitch range in octaves, semitones and cents. ...
Definition: Pitch.cpp:164
static QString getPitchLabelForFrequency(double frequency, double concertA=0.0, bool useFlats=false)
Return a string describing the nearest MIDI pitch to the given frequency, with cents offset...
Definition: Pitch.cpp:151
static int getPitchForFrequency(double frequency, float *centsOffsetReturn, double concertA=0.0)
Compatibility version of getPitchForFrequency accepting float pointer argument.
Definition: Pitch.h:57
static void getNoteAndOctaveForPitch(int midiPitch, int &note, int &octave)
Return the note number (0-12 where 0 is C) and octave number for the given MIDI pitch.
Definition: Pitch.cpp:111
static int getPitchForFrequencyDifference(double frequencyA, double frequencyB, float *centsOffsetReturn, double concertA=0.0)
Compatibility version of getPitchForFrequencyDifference accepting float pointer argument.
Definition: Pitch.h:89
Definition: Pitch.h:21
static bool isFrequencyInMidiRange(double frequency, double concertA=0.0)
Return true if the given frequency falls within the range of MIDI note pitches, plus or minus half a ...
Definition: Pitch.cpp:205
static int getPitchForFrequencyDifference(double frequencyA, double frequencyB, double *centsOffsetReturn=0, double concertA=0.0)
Return the nearest MIDI pitch range to the given frequency range, that is, the difference in MIDI pit...
Definition: Pitch.cpp:61
static int getPitchForFrequency(double frequency, double *centsOffsetReturn=0, double concertA=0.0)
Return the nearest MIDI pitch to the given frequency.
Definition: Pitch.cpp:35
static QString getPitchLabel(int midiPitch, double centsOffset=0, bool useFlats=false)
Return a string describing the given MIDI pitch, with optional cents offset.
Definition: Pitch.cpp:135