From cbe526ae135a0ba47b3d097e3f4fb7d4d295adff Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 10 Oct 2023 03:18:51 -0700 Subject: [PATCH] Version 1.0 Added ms SONG to MIDI converter Now ms scores timings will be converted properly --- tegridy-tools/TMIDIX.py | 70 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/tegridy-tools/TMIDIX.py b/tegridy-tools/TMIDIX.py index c8bae33..9d7197c 100644 --- a/tegridy-tools/TMIDIX.py +++ b/tegridy-tools/TMIDIX.py @@ -41,9 +41,7 @@ # Please see TMIDI 2.3/tegridy-tools repo for full MIDI.py module code # # Or you can always download the latest full version from: -# -# https://pjb.com.au/ -# https://peterbillam.gitlab.io/miditools/ +# https://pjb.com.au/ # # Copyright 2020 Peter Billam # @@ -1624,6 +1622,72 @@ def Tegridy_SONG_to_MIDI_Converter(SONG, print('Done! Enjoy! :)') return detailed_MIDI_stats + +################################################################################### + +def Tegridy_ms_SONG_to_MIDI_Converter(SONG, + output_signature = 'Tegridy TMIDI Module', + track_name = 'Composition Track', + list_of_MIDI_patches = [0, 24, 32, 40, 42, 46, 56, 71, 73, 0, 0, 0, 0, 0, 0, 0], + output_file_name = 'TMIDI-Composition', + text_encoding='ISO-8859-1', + verbose=True): + + '''Tegridy milisecond SONG to MIDI Converter + + Input: Input ms SONG in TMIDI ms SONG/MIDI.py ms Score format + Output MIDI Track 0 name / MIDI Signature + Output MIDI Track 1 name / Composition track name + List of 16 MIDI patch numbers for output MIDI. Def. is MuseNet compatible patches. + Output file name w/o .mid extension. + Optional text encoding if you are working with text_events/lyrics. This is especially useful for Karaoke. Please note that anything but ISO-8859-1 is a non-standard way of encoding text_events according to MIDI specs. + + Output: MIDI File + Detailed MIDI stats + + Project Los Angeles + Tegridy Code 2020''' + + if verbose: + print('Converting to MIDI. Please stand-by...') + + output_header = [1000, + [['set_tempo', 0, 1000000], + ['time_signature', 0, 4, 2, 24, 8], + ['track_name', 0, bytes(output_signature, text_encoding)]]] + + patch_list = [['patch_change', 0, 0, list_of_MIDI_patches[0]], + ['patch_change', 0, 1, list_of_MIDI_patches[1]], + ['patch_change', 0, 2, list_of_MIDI_patches[2]], + ['patch_change', 0, 3, list_of_MIDI_patches[3]], + ['patch_change', 0, 4, list_of_MIDI_patches[4]], + ['patch_change', 0, 5, list_of_MIDI_patches[5]], + ['patch_change', 0, 6, list_of_MIDI_patches[6]], + ['patch_change', 0, 7, list_of_MIDI_patches[7]], + ['patch_change', 0, 8, list_of_MIDI_patches[8]], + ['patch_change', 0, 9, list_of_MIDI_patches[9]], + ['patch_change', 0, 10, list_of_MIDI_patches[10]], + ['patch_change', 0, 11, list_of_MIDI_patches[11]], + ['patch_change', 0, 12, list_of_MIDI_patches[12]], + ['patch_change', 0, 13, list_of_MIDI_patches[13]], + ['patch_change', 0, 14, list_of_MIDI_patches[14]], + ['patch_change', 0, 15, list_of_MIDI_patches[15]], + ['track_name', 0, bytes(track_name, text_encoding)]] + + output = output_header + [patch_list + SONG] + + midi_data = score2midi(output, text_encoding) + detailed_MIDI_stats = score2stats(output) + + with open(output_file_name + '.mid', 'wb') as midi_file: + midi_file.write(midi_data) + midi_file.close() + + if verbose: + print('Done! Enjoy! :)') + + return detailed_MIDI_stats + ################################################################################### def Tegridy_SONG_to_Full_MIDI_Converter(SONG,