Skip to content

Instantly share code, notes, and snippets.

@kelegorm
Last active December 26, 2023 21:55
Show Gist options
  • Save kelegorm/3963ccfb4a4b22bc8f3e0fc242d39bb4 to your computer and use it in GitHub Desktop.
Save kelegorm/3963ccfb4a4b22bc8f3e0fc242d39bb4 to your computer and use it in GitHub Desktop.
Chord Trainer
import 'dart:math';
void main() {
Chord chord = genChord();
print(chordToRussian(chord));
}
Chord genChord() {
final keyIdx = Random().nextInt(12);
final key = Key.values[keyIdx];
final type = CType.values[Random().nextInt(4)];
return Chord(key, type: type);
}
final tooSimpleChords = <Chord>{
const Chord(Key.C, ),
const Chord(Key.D, type: CType.min),
const Chord(Key.E, type: CType.min),
const Chord(Key.F, ),
const Chord(Key.G, ),
const Chord(Key.A, type: CType.min),
const Chord(Key.B, type: CType.dim),
};
class Chord {
final Key key;
final CType type;
final Key bassKey;
const Chord(this.key, {this.type = CType.maj, Key? bassKey})
: this.bassKey = bassKey ?? key;
}
String chordToRussian(Chord ch) {
String res = switch(ch.key) {
Key.A => 'Ля',
Key.Ab => 'Ля бемоль',
Key.B => 'Си',
Key.Bb => 'Си бемоль',
Key.C => 'До',
Key.D => 'Ре',
Key.Db => 'Ре бемоль',
Key.E => 'Ми',
Key.Eb => 'Ми бемоль',
Key.F => 'Фа',
Key.G => 'Соль',
Key.Gb => 'Соль бемоль',
};
if (ch.type != CType.maj) {
res += switch(ch.type) {
CType.maj => ' Мажор',
CType.min => ' Минор',
CType.dim => ' Уменьшенный',
CType.aug => ' Увеличенный',
};
}
return res;
}
enum CType {
maj, min, dim, aug,
}
enum Key {
Ab, A,
Bb, B,
C,
Db, D,
Eb, E,
F,
Gb, G,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment