tonal 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tonal/__init__.py +0 -0
- tonal/chords.py +277 -0
- tonal/converters.py +122 -0
- tonal/util.py +23 -0
- tonal-0.0.2.dist-info/LICENSE +21 -0
- tonal-0.0.2.dist-info/METADATA +64 -0
- tonal-0.0.2.dist-info/RECORD +9 -0
- tonal-0.0.2.dist-info/WHEEL +5 -0
- tonal-0.0.2.dist-info/top_level.txt +1 -0
tonal/__init__.py
ADDED
|
File without changes
|
tonal/chords.py
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"""Tools for chords and chord progressions."""
|
|
2
|
+
|
|
3
|
+
from mido import MidiFile, MidiTrack, Message
|
|
4
|
+
import subprocess
|
|
5
|
+
from typing import Sequence, Tuple, Callable, Mapping, Dict
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
from config2py import process_path
|
|
9
|
+
from sonify.util import (
|
|
10
|
+
DFLT_OUTPUT_NAME,
|
|
11
|
+
DFLT_MIDI_OUTPUT,
|
|
12
|
+
DFLT_SOUNDFONT,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Note = int
|
|
17
|
+
Notes = Sequence[Note]
|
|
18
|
+
Chord = str
|
|
19
|
+
ChordTimed = Tuple[Chord, Notes]
|
|
20
|
+
ChordSequence = Sequence[ChordTimed]
|
|
21
|
+
# ChordDefinitions = Mapping[Chord, Notes]
|
|
22
|
+
ChordDefinitions = Callable[[Chord], Notes]
|
|
23
|
+
ChordRenderer = Callable[[Notes, MidiTrack, int], None]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
DFLT_CHORD_SEQUENCE = [
|
|
27
|
+
('Bdim', 120),
|
|
28
|
+
('Em11', 120),
|
|
29
|
+
('Amin9', 120),
|
|
30
|
+
('Dm7', 120),
|
|
31
|
+
'G7',
|
|
32
|
+
'Cmaj7',
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Define root notes to MIDI note numbers
|
|
37
|
+
root_notes: Dict[str, int] = {
|
|
38
|
+
'C': 60,
|
|
39
|
+
'C#': 61,
|
|
40
|
+
'Db': 61,
|
|
41
|
+
'D': 62,
|
|
42
|
+
'D#': 63,
|
|
43
|
+
'Eb': 63,
|
|
44
|
+
'E': 64,
|
|
45
|
+
'F': 65,
|
|
46
|
+
'F#': 66,
|
|
47
|
+
'Gb': 66,
|
|
48
|
+
'G': 67,
|
|
49
|
+
'G#': 68,
|
|
50
|
+
'Ab': 68,
|
|
51
|
+
'A': 69,
|
|
52
|
+
'A#': 70,
|
|
53
|
+
'Bb': 70,
|
|
54
|
+
'B': 71,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# TODO: Verify completeness and more chord definitions if needed
|
|
58
|
+
# TODO: See if defs can be infered from parsing the chord names
|
|
59
|
+
# Define quality and extension intervals
|
|
60
|
+
quality_extensions: Dict[str, Sequence[int]] = {
|
|
61
|
+
'': [0, 4, 7], # Major triad, 'C' -> 'Cmaj
|
|
62
|
+
'maj': [0, 4, 7], # Major triad
|
|
63
|
+
'min': [0, 3, 7], # Minor triad
|
|
64
|
+
'dim': [0, 3, 6], # Diminished triad
|
|
65
|
+
'aug': [0, 4, 8], # Augmented triad
|
|
66
|
+
'7': [0, 4, 7, 10], # Dominant 7th
|
|
67
|
+
'maj7': [0, 4, 7, 11], # Major 7th
|
|
68
|
+
'min7': [0, 3, 7, 10], # Minor 7th
|
|
69
|
+
'minmaj7': [0, 3, 7, 11], # Minor major 7th
|
|
70
|
+
'dim7': [0, 3, 6, 9], # Diminished 7th
|
|
71
|
+
'hdim7': [0, 3, 6, 10], # Half-diminished 7th
|
|
72
|
+
'aug7': [0, 4, 8, 10], # Augmented 7th
|
|
73
|
+
'6': [0, 4, 7, 9], # Major 6th
|
|
74
|
+
'min6': [0, 3, 7, 9], # Minor 6th
|
|
75
|
+
'9': [0, 4, 7, 10, 14], # Dominant 9th
|
|
76
|
+
'maj9': [0, 4, 7, 11, 14], # Major 9th
|
|
77
|
+
'min9': [0, 3, 7, 10, 14], # Minor 9th
|
|
78
|
+
'11': [0, 4, 7, 10, 14, 17], # Dominant 11th
|
|
79
|
+
'maj11': [0, 4, 7, 11, 14, 17], # Major 11th
|
|
80
|
+
'min11': [0, 3, 7, 10, 14, 17], # Minor 11th
|
|
81
|
+
'13': [0, 4, 7, 10, 14, 17, 21], # Dominant 13th
|
|
82
|
+
'maj13': [0, 4, 7, 11, 14, 17, 21], # Major 13th
|
|
83
|
+
'min13': [0, 3, 7, 10, 14, 17, 21], # Minor 13th
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# add aliases
|
|
87
|
+
# TODO: Make a framework for user-defined aliases
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def add_aliases(quality_extensions):
|
|
91
|
+
for _qe in quality_extensions:
|
|
92
|
+
if _qe.startswith('maj'):
|
|
93
|
+
yield _qe.replace('maj', 'M'), quality_extensions[_qe]
|
|
94
|
+
elif _qe.startswith('min'):
|
|
95
|
+
yield _qe.replace('min', 'm'), quality_extensions[_qe]
|
|
96
|
+
elif _qe.startswith('dim'):
|
|
97
|
+
yield _qe.replace('dim', '°'), quality_extensions[_qe]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
quality_extensions.update(dict(add_aliases(quality_extensions)))
|
|
101
|
+
|
|
102
|
+
# TODO: Change extension definitions to base one, and define chord inversions on top
|
|
103
|
+
|
|
104
|
+
# chord_pattern = re.compile(r'([A-Ga-g][#b]?)(maj|min|dim|aug)?([0-9]*)')
|
|
105
|
+
chord_note_pattern = re.compile(r'([A-Ga-g][#b]?)')
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def parse_root(chord: str) -> str:
|
|
109
|
+
match = chord_note_pattern.match(chord)
|
|
110
|
+
if match:
|
|
111
|
+
return match.group(1)
|
|
112
|
+
else:
|
|
113
|
+
raise ValueError(f"Invalid chord: {chord}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def chord_to_notes(chord: Chord) -> Notes:
|
|
117
|
+
"""
|
|
118
|
+
Parse a chord string and return the corresponding sequence of MIDI note numbers.
|
|
119
|
+
|
|
120
|
+
:param chord: The chord string (e.g., 'Cmaj7').
|
|
121
|
+
:return: A sequence of MIDI note numbers representing the chord.
|
|
122
|
+
"""
|
|
123
|
+
root = parse_root(chord)
|
|
124
|
+
quality_extension = chord[len(root) :]
|
|
125
|
+
root_midi = root_notes.get(root)
|
|
126
|
+
# print(root, root_midi, quality_extension)
|
|
127
|
+
|
|
128
|
+
if root_midi is None:
|
|
129
|
+
raise ValueError(f"Unknown root note: {root}")
|
|
130
|
+
|
|
131
|
+
intervals = quality_extensions.get(quality_extension)
|
|
132
|
+
|
|
133
|
+
if intervals is None:
|
|
134
|
+
raise ValueError(f"Unknown quality/extension: {quality_extension}")
|
|
135
|
+
|
|
136
|
+
return [root_midi + interval for interval in intervals]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if not os.path.exists(DFLT_SOUNDFONT):
|
|
140
|
+
from warnings import warn
|
|
141
|
+
|
|
142
|
+
warn(f"Soundfont not found at {DFLT_SOUNDFONT}")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
chord_renders = {}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def register_chord_render(chord_renderer: ChordRenderer, name=None):
|
|
149
|
+
if name is None:
|
|
150
|
+
name = chord_renderer.__name__
|
|
151
|
+
chord_renders[chord_renderer.__name__] = chord_renderer
|
|
152
|
+
return chord_renderer
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@register_chord_render
|
|
156
|
+
def play_simultaneously(
|
|
157
|
+
notes: Sequence[int], track: MidiTrack, duration: int, *, velocity=64
|
|
158
|
+
):
|
|
159
|
+
v = velocity
|
|
160
|
+
for note in notes:
|
|
161
|
+
track.append(Message('note_on', note=note, velocity=v, time=0))
|
|
162
|
+
_notes = iter(notes)
|
|
163
|
+
track.append(Message('note_off', note=next(_notes), velocity=v, time=duration))
|
|
164
|
+
for note in _notes:
|
|
165
|
+
track.append(Message('note_off', note=note, velocity=v, time=0))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# TODO: Need a better implementation for arpeggios.
|
|
169
|
+
@register_chord_render
|
|
170
|
+
def play_arpeggio(
|
|
171
|
+
notes: Sequence[int], track: MidiTrack, duration: int, *, velocity=64
|
|
172
|
+
):
|
|
173
|
+
v = velocity
|
|
174
|
+
note_duration = duration // len(notes)
|
|
175
|
+
current_time = 0
|
|
176
|
+
for note in notes:
|
|
177
|
+
track.append(Message('note_on', note=note, velocity=v, time=current_time))
|
|
178
|
+
current_time += note_duration
|
|
179
|
+
track.append(Message('note_off', note=note, velocity=v, time=current_time))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def resolve_chord_render(chord_renderer: ChordRenderer) -> ChordRenderer:
|
|
183
|
+
if isinstance(chord_renderer, str):
|
|
184
|
+
name = chord_renderer
|
|
185
|
+
chord_renderer = chord_renders.get(name)
|
|
186
|
+
if chord_renderer is None:
|
|
187
|
+
raise ValueError(
|
|
188
|
+
f'Unknown chord renderer: {name}. '
|
|
189
|
+
'(Available: {", ".join(chord_renders)}). '
|
|
190
|
+
'You can register a new chord renderer with `register_chord_render`.'
|
|
191
|
+
)
|
|
192
|
+
return chord_renderer
|
|
193
|
+
return chord_renderer
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
DFLT_DURATION = 240 * 4
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def process_chord_sequence(
|
|
200
|
+
chord_sequence: ChordSequence, default_duration=DFLT_DURATION
|
|
201
|
+
):
|
|
202
|
+
"""Preprocess a chord sequence, to make sure to add time, etc."""
|
|
203
|
+
for chord in chord_sequence:
|
|
204
|
+
if isinstance(chord, str):
|
|
205
|
+
yield chord, default_duration
|
|
206
|
+
elif isinstance(chord, tuple):
|
|
207
|
+
yield chord
|
|
208
|
+
else:
|
|
209
|
+
raise ValueError(f"Invalid chord: {chord}")
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def chords_to_midi(
|
|
213
|
+
chord_sequence: ChordSequence = DFLT_CHORD_SEQUENCE,
|
|
214
|
+
*,
|
|
215
|
+
output_file: str = DFLT_MIDI_OUTPUT,
|
|
216
|
+
render_chord: ChordRenderer = play_simultaneously,
|
|
217
|
+
chord_definitions: ChordDefinitions = chord_to_notes,
|
|
218
|
+
):
|
|
219
|
+
"""
|
|
220
|
+
Generate a MIDI file from a chord sequence.
|
|
221
|
+
|
|
222
|
+
:param chord_sequence: List of tuples containing chords and their duration.
|
|
223
|
+
:param chord_definitions: Dictionary mapping chords to MIDI note patterns.
|
|
224
|
+
:param output_file: Name of the output MIDI file.
|
|
225
|
+
:param render_chord: Function defining how the chords should be played.
|
|
226
|
+
"""
|
|
227
|
+
midi = MidiFile()
|
|
228
|
+
track = MidiTrack()
|
|
229
|
+
midi.tracks.append(track)
|
|
230
|
+
|
|
231
|
+
render_chord = resolve_chord_render(render_chord)
|
|
232
|
+
chord_sequence = process_chord_sequence(chord_sequence)
|
|
233
|
+
|
|
234
|
+
track.append(Message('program_change', program=0, time=0)) # Acoustic Grand Piano
|
|
235
|
+
|
|
236
|
+
for chord, duration in chord_sequence:
|
|
237
|
+
pattern = chord_definitions(chord)
|
|
238
|
+
if pattern:
|
|
239
|
+
render_chord(pattern, track, duration)
|
|
240
|
+
|
|
241
|
+
if output_file:
|
|
242
|
+
midi.save(output_file)
|
|
243
|
+
return output_file
|
|
244
|
+
else:
|
|
245
|
+
return midi
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def chords_to_wav(
|
|
249
|
+
chord_sequence: ChordSequence = DFLT_CHORD_SEQUENCE,
|
|
250
|
+
name: str = DFLT_OUTPUT_NAME,
|
|
251
|
+
*,
|
|
252
|
+
chord_definitions: ChordDefinitions = chord_to_notes,
|
|
253
|
+
soundfont: str = DFLT_SOUNDFONT,
|
|
254
|
+
render_chord: ChordRenderer = play_simultaneously,
|
|
255
|
+
):
|
|
256
|
+
"""
|
|
257
|
+
Generate a WAV file directly from a chord sequence.
|
|
258
|
+
|
|
259
|
+
:param chord_sequence: List of tuples containing chords and their duration.
|
|
260
|
+
:param name: Base name for the output MIDI and WAV files.
|
|
261
|
+
:param chord_definitions: Dictionary mapping chords to MIDI note patterns.
|
|
262
|
+
:param soundfont: Path to the SoundFont file.
|
|
263
|
+
:param render_chord: Function defining how the chords should be played.
|
|
264
|
+
"""
|
|
265
|
+
from sonify.converters import midi_to_wav
|
|
266
|
+
|
|
267
|
+
midi_file = f'{name}.mid'
|
|
268
|
+
wav_file = f'{name}.wav'
|
|
269
|
+
|
|
270
|
+
chords_to_midi(
|
|
271
|
+
chord_sequence,
|
|
272
|
+
chord_definitions=chord_definitions,
|
|
273
|
+
output_file=midi_file,
|
|
274
|
+
render_chord=render_chord,
|
|
275
|
+
)
|
|
276
|
+
midi_to_wav(midi_file=midi_file, output_wav=wav_file, soundfont=soundfont)
|
|
277
|
+
return wav_file
|
tonal/converters.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Convert music into various formats."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from sonify.util import DFLT_MIDI_OUTPUT, DFLT_SOUNDFONT, DFLT_WAV_OUTPUT
|
|
5
|
+
|
|
6
|
+
dflt_format_for_extension = {
|
|
7
|
+
'.midi': 'midi',
|
|
8
|
+
'.mid': 'midi',
|
|
9
|
+
'.xml': 'musicxml',
|
|
10
|
+
'.musicxml': 'musicxml',
|
|
11
|
+
'.wav': 'wav',
|
|
12
|
+
'.png': 'image',
|
|
13
|
+
'.jpg': 'image',
|
|
14
|
+
'.jpeg': 'image',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
dflt_extension_for_format = {v: k for k, v in dflt_format_for_extension.items()}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def format_of_filepath(
|
|
21
|
+
filepath: str, *, format_for_extension=dflt_format_for_extension
|
|
22
|
+
) -> str:
|
|
23
|
+
"""Return the format of a file."""
|
|
24
|
+
ext = os.path.splitext(filepath)[-1].lower()
|
|
25
|
+
return format_for_extension.get(ext, ext)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def replace_extension(src: str, dest_extension: str) -> str:
|
|
29
|
+
return src.replace(os.path.splitext(src)[-1], dest_extension)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def ensure_dest_filepath(
|
|
33
|
+
src: str,
|
|
34
|
+
dest: str,
|
|
35
|
+
*,
|
|
36
|
+
dest_format: str = None,
|
|
37
|
+
extension_for_format=dflt_extension_for_format,
|
|
38
|
+
) -> str:
|
|
39
|
+
"""Ensure that a destination filepath is given."""
|
|
40
|
+
if dest is None:
|
|
41
|
+
src_ext = os.path.splitext(src)[-1]
|
|
42
|
+
dest_ext = extension_for_format.get(dest_format, f".{dest_format}")
|
|
43
|
+
dest = src.replace(src_ext, dest_ext)
|
|
44
|
+
return dest
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def convert(
|
|
48
|
+
src: str,
|
|
49
|
+
dest: str,
|
|
50
|
+
*,
|
|
51
|
+
src_format: str = None,
|
|
52
|
+
dest_format: str = None,
|
|
53
|
+
format_for_extension=dflt_format_for_extension,
|
|
54
|
+
) -> str:
|
|
55
|
+
src_format = format_of_filepath(src)
|
|
56
|
+
|
|
57
|
+
# if dest is just an extension, add it to the source filename to make the actual filepath
|
|
58
|
+
if dest in format_for_extension:
|
|
59
|
+
dest_extension = dest
|
|
60
|
+
dest = replace_extension(src, dest_extension)
|
|
61
|
+
|
|
62
|
+
dest_format = format_of_filepath(dest)
|
|
63
|
+
|
|
64
|
+
# print(locals())
|
|
65
|
+
if src_format == 'musicxml' and dest_format == 'midi':
|
|
66
|
+
return musicxml_to_midi(src, dest)
|
|
67
|
+
if src_format == 'midi' and dest_format == 'wav':
|
|
68
|
+
return midi_to_wav(src, dest)
|
|
69
|
+
if src_format == 'image' and dest_format == 'musicxml':
|
|
70
|
+
return image_to_musicxml(src)
|
|
71
|
+
raise ValueError(f"Unsupported conversion: {src_format} -> {dest_format}")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def image_to_musicxml(
|
|
75
|
+
image: str, *, enable_debug=False, enable_cache=False, remove_teaser_file=True
|
|
76
|
+
):
|
|
77
|
+
"""Convert and image of a music score into a musicxml file."""
|
|
78
|
+
from homr.main import process_image
|
|
79
|
+
|
|
80
|
+
musicxml_filepath, _, teaser_filepath = process_image(
|
|
81
|
+
image, enable_debug=enable_debug, enable_cache=enable_cache
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if remove_teaser_file:
|
|
85
|
+
os.remove(teaser_filepath)
|
|
86
|
+
|
|
87
|
+
return musicxml_filepath
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def musicxml_to_midi(musicxml_path, midi_path=None):
|
|
91
|
+
from music21 import converter
|
|
92
|
+
|
|
93
|
+
if midi_path is None:
|
|
94
|
+
midi_path = musicxml_path.replace('.musicxml', '.mid')
|
|
95
|
+
score = converter.parse(musicxml_path)
|
|
96
|
+
score.write('midi', fp=midi_path)
|
|
97
|
+
return midi_path
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def midi_to_wav(
|
|
101
|
+
midi_file: str,
|
|
102
|
+
output_wav: str = None,
|
|
103
|
+
*,
|
|
104
|
+
soundfont: str = DFLT_SOUNDFONT,
|
|
105
|
+
):
|
|
106
|
+
"""
|
|
107
|
+
Synthesize audio from a MIDI file using FluidSynth.
|
|
108
|
+
|
|
109
|
+
:param midi_file: Name of the input MIDI file.
|
|
110
|
+
:param output_wav: Name of the output WAV file.
|
|
111
|
+
:param soundfont: Path to the SoundFont file.
|
|
112
|
+
|
|
113
|
+
"""
|
|
114
|
+
import subprocess
|
|
115
|
+
|
|
116
|
+
output_wav = ensure_dest_filepath(midi_file, output_wav, dest_format='wav')
|
|
117
|
+
|
|
118
|
+
subprocess.run(
|
|
119
|
+
['fluidsynth', '-ni', soundfont, midi_file, '-F', output_wav, '-r', '44100']
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
return output_wav
|
tonal/util.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Utils for sonify."""
|
|
2
|
+
|
|
3
|
+
from importlib.resources import files
|
|
4
|
+
from functools import partial
|
|
5
|
+
from dol import Pipe
|
|
6
|
+
from config2py import (
|
|
7
|
+
process_path,
|
|
8
|
+
simple_config_getter,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
pkg_name = 'sonify'
|
|
12
|
+
|
|
13
|
+
data_files = files(pkg_name) / 'data'
|
|
14
|
+
|
|
15
|
+
get_config = simple_config_getter(pkg_name)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
DFLT_OUTPUT_NAME = 'audio_output'
|
|
19
|
+
DFLT_MIDI_OUTPUT = f"{DFLT_OUTPUT_NAME}.mid"
|
|
20
|
+
DFLT_WAV_OUTPUT = f"{DFLT_OUTPUT_NAME}.wav"
|
|
21
|
+
DFLT_SOUNDFONT = process_path(
|
|
22
|
+
get_config('SONIFY_DFLT_SOUNDFONT_PATH'),
|
|
23
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [year] [fullname]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: tonal
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Tools for music analysis and generation
|
|
5
|
+
Home-page: https://github.com/thorwhalen/tonal
|
|
6
|
+
Author: Thor Whalen
|
|
7
|
+
License: mit
|
|
8
|
+
Platform: any
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# tonal
|
|
14
|
+
Tools for music analysis and generation
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
To install: ```pip install tonal```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Examples
|
|
21
|
+
|
|
22
|
+
## chords
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from tonal import chords_to_wav
|
|
27
|
+
|
|
28
|
+
chord_sequence = [
|
|
29
|
+
('Bdim', 120),
|
|
30
|
+
('Em11', 120),
|
|
31
|
+
('Amin9', 120),
|
|
32
|
+
('Dm7', 120),
|
|
33
|
+
'G7',
|
|
34
|
+
'Cmaj7',
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
wav_filepath = chords_to_wav(chord_sequence)
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you have [hum](https://pypi.org/project/hum/) you can use it to diplay (and hear)
|
|
42
|
+
the sound:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from hum import Sound
|
|
46
|
+
Sound.from_file(wav_filepath).display()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Change the way the chords are played, and what the name (really, filepath) of the
|
|
53
|
+
midi and wav files produce are.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from tonal.chords import play_arpeggio
|
|
57
|
+
|
|
58
|
+
Sound.from_file(
|
|
59
|
+
chords_to_wav(chord_sequence, name='test_arpeggio', render_chord=play_arpeggio)
|
|
60
|
+
).display()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+

|
|
64
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
tonal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tonal/chords.py,sha256=b4MF11qE4O5vRIXV6Mrh2U36jvdo9aY4kGTDUdgvVRA,8371
|
|
3
|
+
tonal/converters.py,sha256=fE1IUKhZtv7FfoATyU6WzltdgOeGBdznKBWgUHeZAlU,3378
|
|
4
|
+
tonal/util.py,sha256=q5OP27Oh_2wMqt_WLO7mraFe2RCBjpfsoPgRwvgOKH0,493
|
|
5
|
+
tonal-0.0.2.dist-info/LICENSE,sha256=ACwmltkrXIz5VsEQcrqljq-fat6ZXAMepjXGoe40KtE,1069
|
|
6
|
+
tonal-0.0.2.dist-info/METADATA,sha256=4jG8tk88Ls1PPDO29efklOpQXTb5f8lro8Oe0SN9SeY,1243
|
|
7
|
+
tonal-0.0.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
8
|
+
tonal-0.0.2.dist-info/top_level.txt,sha256=1B3VlZSwyJO8s0DmUvMAdr3xvisKTRjRF21b2FXv2WQ,6
|
|
9
|
+
tonal-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tonal
|