MCPcopy Create free account
hub / github.com/LancePutnam/Gamma / main

Function main

examples/algorithmic/noteFuncs.cpp:14–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace gam;
13
14int main(){
15
16 /*
17 scl::freq returns a frequency, in Hz, from a note string consisting of a
18 pitch class letter followed by an (optional) accidental and lastly an
19 octave number where 4 is the middle octave.
20 */
21
22 // Middle C
23 printf("\"c 4\" = %g Hz\n", scl::freq("c 4"));
24 printf("\"C4\" = %g Hz\n", scl::freq("C4"));
25
26 // Middle C sharp
27 printf("\"c+4\" = %g Hz\n", scl::freq("c+4"));
28 printf("\"C#4\" = %g Hz\n", scl::freq("C#4"));
29
30 // Middle C flat
31 printf("\"c-4\" = %g Hz\n", scl::freq("c-4"));
32 printf("\"Cb4\" = %g Hz\n", scl::freq("Cb4"));
33
34 // Low A
35 printf("\"a3\" = %g Hz\n", scl::freq("a3"));
36
37 // The C major scale
38 printf("\nFrequencies of the C-major scale (middle octave):\n");
39 printf("%g, %g, %g, %g, %g, %g, %g, %g\n",
40 scl::freq("c4"), scl::freq("d4"), scl::freq("e4"), scl::freq("f4"),
41 scl::freq("g4"), scl::freq("a4"), scl::freq("b4"), scl::freq("c5")
42 );
43
44
45 /*
46 We can use scl::nearest to get the closest note number within a specified
47 pitch class set. This is useful for mapping arbitrary values onto notes in a
48 musical scale.
49 The first argument is the note number to match, the second is a string
50 containing the scale's half-step intervals, and the third argument specifies
51 the modulus or divisions per octave (default is 12).
52 */
53
54 // Major scale
55 printf("%g\n", scl::nearest(4.1, "2212221"));
56
57 // Minor scale
58 printf("%g\n", scl::nearest(4.1, "2122212"));
59
60 // Major pentatonic scale
61 printf("%g\n", scl::nearest( 1.1, "22323"));
62 printf("%g\n", scl::nearest( 4.1, "22323"));
63 printf("%g\n", scl::nearest(10.7, "22323"));
64
65
66 /*
67 scl::ratioET computes frequency ratios within a specified
68 equal-temperament tuning system. The first argument is the note number, the
69 second is the number of divisions per octave (default is 12) and the third
70 is the base multiplier of the octave (default is 2).
71 */

Callers

nothing calls this directly

Calls 3

freqFunction · 0.85
ratioETFunction · 0.85
nearestFunction · 0.50

Tested by

no test coverage detected