Browse Source

Initial commit

Dionysus 5 months ago
commit
fcbaa135f1
Signed by: acidvegas <acid.vegas@acid.vegas> GPG Key ID: 05114B46832BDBDB
3 changed files with 237 additions and 0 deletions
  1. 78
    0
      mzk/constants.py
  2. 153
    0
      mzk/functions.py
  3. 6
    0
      mzk/main.py

+ 78
- 0
mzk/constants.py View File

@@ -0,0 +1,78 @@
1
+#!/usr/bin/env python
2
+# mzk music theory helper - developed by acidvegas in python (https://acid.vegas/mzk)
3
+# constants.py
4
+
5
+circle = '''                        major
6
+
7
+                          C
8
+               F                     G
9
+                          ♮
10
+                  1♭              1♯
11
+                          a
12
+      B♭             d         c               D
13
+           2♭                           2♯
14
+                g       minor       b
15
+
16
+
17
+    E♭   3♭   c                       f♯   3♯   A
18
+
19
+
20
+                f                   c♯
21
+           4♭                            4
22
+      A♭            b♭         g♯             E
23
+                        e♭/d♯
24
+              5♭/7♯               7♭/5♯
25
+                        6♭/6♯
26
+              D♭                     B
27
+                        G♭/F♯
28
+          C♯                           C♭'''
29
+
30
+colors = {
31
+	'gray'  : '\033[0;90m',
32
+	'red'   : '\033[0;91m',
33
+	'green' : '\033[0;92m',
34
+	'reset' : '\033[0m'
35
+}
36
+
37
+intervals = {
38
+	'unison'           : {'semitones':0,  'short_name':'P1' },
39
+	'minor_second'     : {'semitones':1,  'short_name':'m2' },
40
+	'major_second'     : {'semitones':2,  'short_name':'M2' },
41
+	'minor_third'      : {'semitones':3,  'short_name':'m3' },
42
+	'major_third'      : {'semitones':4,  'short_name':'M3' },
43
+	'perfect_fourth'   : {'semitones':5,  'short_name':'P4' },
44
+	'augmented_fourth' : {'semitones':6,  'short_name':'+4' },
45
+	'diminished_fifth' : {'semitones':6,  'short_name':'d5' },
46
+	'perfect_fifth'    : {'semitones':7,  'short_name':'P5' },
47
+	'minor_sixth'      : {'semitones':8,  'short_name':'m6' },
48
+	'major_sixth'      : {'semitones':9,  'short_name':'M6' },
49
+	'minor_seventh'    : {'semitones':10, 'short_name':'m7' },
50
+	'major_seventh'    : {'semitones':11, 'short_name':'M7' },
51
+	'perfect_octave'   : {'semitones':12, 'short_name':'8va'}
52
+}
53
+
54
+notes         = ('A', 'A#', 'B',   'C',  'C#', 'D',  'D#',  'E',    'F',  'F#', 'G',  'G#'     )
55
+numerals      = ('I', 'II', 'III', 'IV', 'V',  'VI', 'VII', 'VIII', 'IX', 'X',  'XI', 'XII'    )
56
+scale_degrees = ('tonic','supertonic','mediant','subdominant','dominant''submediant','subtonic')
57
+
58
+scales = {
59
+	'algerian'              :  '2131131',
60
+	'aeolian'               :  '2122122',
61
+	'blues'                 :   '321132',
62
+	'chromatic'             :  '1111111',
63
+	'dorian'                :  '2122212',
64
+	'half_whole_diminished' : '12121212',
65
+	'harmonic_minor'        :  '2122131',
66
+	'ionian'                :  '2212221',
67
+	'locrian'               :  '1221222',
68
+	'lydian'                :  '2221221',
69
+	'major'                 :  '2212221',
70
+	'major_pentatonic'      :    '22323',
71
+	'melodic_minor'         :  '2122221',
72
+	'mixolydian'            :  '2212212',
73
+	'natural_minor'         :  '2122122',
74
+	'persian'               :  '1311231',
75
+	'phrygian'              :  '1222122',
76
+	'whole_half_diminished' : '21212121',
77
+	'whole_tone'            :  '2222222'
78
+}

+ 153
- 0
mzk/functions.py View File

@@ -0,0 +1,153 @@
1
+#!/usr/bin/env python
2
+# mzk music theory helper - developed by acidvegas in python (https://acid.vegas/mzk)
3
+# functions.py
4
+
5
+import constants
6
+
7
+def generate_notes(key):
8
+	notes = ['A','A#','B','C','C#','D','D#','E','F','F#','G','G#']
9
+	while notes[0] != key:
10
+		notes.append(notes.pop(0))
11
+	return notes
12
+
13
+def generate_scale(string, scale_notes, full=False):
14
+	notes = generate_notes(string.upper())*2 if full else generate_notes(string.upper())
15
+	notes.append(notes[0]) # add root note to the end
16
+	for index,note in enumerate(notes):
17
+		if note in scale_notes:
18
+			notes[index] = notes[index].center(5, '-')
19
+		else:
20
+			notes[index] = '-'*5
21
+	return notes
22
+
23
+def get_pattern(pattern):
24
+	new_pattern = list()
25
+	for step in pattern:
26
+		if   step == '1' : new_pattern.append('H')
27
+		elif step == '2' : new_pattern.append('W')
28
+		elif step == '3' : new_pattern.append('WH')
29
+	return ' '.join(new_pattern)
30
+
31
+def scale(type, key):
32
+	last = 0
33
+	notes = generate_notes(key)
34
+	scale_notes = [notes[0],]
35
+	for step in scales[type]:
36
+		last += int(step)
37
+		if last >= len(notes):
38
+			last -= len(notes)
39
+		scale_notes.append(notes[last])
40
+	return scale_notes
41
+
42
+def print_chord():
43
+	# todo: finish this
44
+	print('◯  ⬤ ')
45
+	print('''╳   ╳   ╳   ╳   ╳   ╳
46
+┌───┬───┬───┬───┬───┐
47
+│   │   │   │   │   │
48
+├───┼───┼───┼───┼───┤
49
+│   │   │   │   │   │
50
+├───┼───┼───┼───┼───┤
51
+│   │   │   │   │   │
52
+├───┼───┼───┼───┼───┤
53
+│   │   │   │   │   │
54
+├───┼───┼───┼───┼───┤
55
+│   │   │   │   │   │
56
+└───┴───┴───┴───┴───┘
57
+E   A   D   G   B   e''')
58
+
59
+def print_circle_of_fifths():
60
+	'''
61
+		definition:
62
+			the relationship among the 12 tones of the chromatic scale, their corresponding key signatures, & the associated major/minor keys
63
+
64
+		accidentals:
65
+			sharps - F, C, G, D, A, E, B
66
+			flats  - B, E, A, D, G, C, F
67
+
68
+		intervals:
69
+			unison
70
+			perfect   fifth
71
+			major     sencond
72
+			major     sixth
73
+			major     third
74
+			major     seventh
75
+			augmented fourth
76
+			minor     second
77
+			minor     sixth
78
+			minor     third
79
+			minor     seventh
80
+			perfect   fourth
81
+	'''
82
+	circle = constants.circle.replace('\n',' \n') + ' ' # todo: fix this
83
+	for note in ('major','C','F','B♭','E♭','A♭','D♭','C♯','G♭/F♯','B','C♭','E','A','D','G'): # todo: reverse
84
+		circle = circle.replace(f' {note} ', f' \033[91m{note}\033[0m ')
85
+	for item in ('♮','1♭','2♭','3♭','4♭','5♭/7♯','6♭/6♯','7♭/5♯','4','3♯','2♯','1♯'):
86
+		circle = circle.replace(f' {item} ', f' \033[90m{item}\033[0m ')
87
+	for note in ('minor','a','d','g','c','f','b♭','e♭/d♯','g♯','c♯','f♯','b','c'):
88
+		circle = circle.replace(f' {note} ', f' \033[92m{note}\033[0m ')
89
+	print(circle)
90
+	#print(print_circle_of_fifths.__doc__)
91
+
92
+def print_intervals():
93
+	'''
94
+	definition:
95
+		the distance between two notes or pitches
96
+
97
+	note:
98
+		semitone - half step
99
+		tone     - whole step (b to c & e to f is a tone)
100
+
101
+	types:
102
+		harmonic interval - notes played simultaneously
103
+		melodic  interval - notes played successively
104
+
105
+	makeup:
106
+		quantity - distance between two notes
107
+		quality  - number of semitones between notes
108
+
109
+	qualities:
110
+		major/minor - 2nds, 3rds, 6ths, 7ths
111
+		perfect     - 4ths, 5ths, octaves
112
+		diminished  - minor/perfect - 1 semitone
113
+		augmented   - major/perfect + 1 semitone
114
+	'''
115
+	print('            I N T E R V A L S           ')
116
+	print('┌───────────┬──────────────────┬───────┐')
117
+	print('│ semitones │ quality          │ short │')
118
+	print('├───────────┼──────────────────┼───────┤')
119
+	for interval, info in constants.intervals.items():
120
+		print('│ {0} │ {1} │ {2} │'.format(str(info['semitones']).rjust(9), interval.ljust(16), info['short_name'].ljust(5)))
121
+	print('└───────────┴──────────────────┴───────┘')
122
+	#print(print_intervals.__doc__)
123
+
124
+def print_scale(root, type, full=False):
125
+	frets = (24,147) if full else (12,75)
126
+	print(f'{root.upper()} {type.upper()} SCALE'.center(frets[1]))
127
+	print('  ┌' + '┬'.join('─'*5 for x in range(frets[0])) + '┐')
128
+	print('0 │' + '│'.join(str(x).center(5) for x in range(1,frets[0]+1)) + '│')
129
+	print('  ├' + '┼'.join('─'*5 for x in range(frets[0])) + '┤')
130
+	scale_notes = scale(type, root)
131
+	for string in ('eBGDAE'):
132
+		string_notes = generate_scale(string, scale_notes, full)
133
+		print(string + ' │' + '│'.join(note.center(5, '-') for note in string_notes[1:]) + '│')
134
+	print('  └' + '┴'.join('─'*5 for x in range(frets[0])) + '┘')
135
+	print((', '.join(scale_notes) + ' / ' + get_pattern(scales[type])).rjust(frets[1]))
136
+
137
+def print_scales():
138
+	'''
139
+	definition:
140
+		any set of musical notes ordered by fundamental frequency or pitch
141
+
142
+	note:
143
+		1 - half step
144
+		2 - whole step
145
+		3 - whole step half step'''
146
+	print('               S C A L E S               ')
147
+	print('┌───────────────────────┬─────────────────┐')
148
+	print('│ name                  │ intervals       │')
149
+	print('├───────────────────────┼─────────────────┤')
150
+	for name, pattern in constants.scales.items():
151
+		print(f'│ {name.ljust(21)} │ {get_pattern(pattern).rjust(15)} │')
152
+	print('└───────────────────────┴─────────────────┘')
153
+	#print(print_scales.__doc__)

+ 6
- 0
mzk/main.py View File

@@ -0,0 +1,6 @@
1
+#!/usr/bin/env python
2
+# mzk music theory helper - developed by acidvegas in python (https://acid.vegas/mzk)
3
+# main.py
4
+
5
+import argparser
6
+import sys

Loading…
Cancel
Save