-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_notes.dart
46 lines (43 loc) · 1.01 KB
/
generate_notes.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/// Generated the `notes.dart` file.
import 'dart:io';
import 'dart:math';
/// A4.
const a4 = 440.0;
/// The note names.
const noteNames = {
'c': -9,
'cSharp': -8,
'd': -7,
'dSharp': -6,
'e': -5,
'f': -4,
'fSharp': -3,
'g': -2,
'gSharp': -1,
'a': 0,
'aSharp': 1,
'b': 2,
};
/// Run the program.
void main() {
final stringBuffer = StringBuffer()
..writeln('/// Note values for playing waves.')
..writeln('library notes;');
final a = pow(2.0, 1.0 / 12.0);
var referencePitch = a4 / 8;
var octaveNumber = 1;
while (octaveNumber < 7) {
for (final entry in noteNames.entries) {
final noteName = entry.key;
final difference = entry.value;
final frequency = referencePitch * pow(a, difference);
stringBuffer
..writeln()
..writeln('/// $noteName $octaveNumber.')
..writeln('const $noteName$octaveNumber = $frequency;');
}
octaveNumber++;
referencePitch *= 2;
}
File('lib/notes.dart').writeAsStringSync(stringBuffer.toString());
}