File size: 2,757 Bytes
758037b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
"""Los_Angeles_MIDI_Dataset_CHORDS_DATA_Decoder.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1HKcxhtWFX4zGE8ZxG59pzaWHDxnaxctR

# Los Angeles MIDI Dataset CHORDS DATA Decoder (ver. 1.0)

***

Powered by tegridy-tools: https://github.com/asigalov61/tegridy-tools

***

#### Project Los Angeles

#### Tegridy Code 2024

***

# (SETUP ENVIRONMENT)
"""

#@title Install all dependencies (run only once per session)

!git clone https://github.com/asigalov61/tegridy-tools
!pip install tqdm

#@title Import all needed modules

print('Loading core modules... Please wait...')
import os

import math
import statistics
import random
from collections import Counter
import shutil
import hashlib
from tqdm import tqdm

print('Creating IO dirs...')

if not os.path.exists('/content/CHORDS_DATA'):
    os.makedirs('/content/CHORDS_DATA')

print('Loading TMIDIX module...')
os.chdir('/content/tegridy-tools/tegridy-tools')

import TMIDIX

print('Done!')

os.chdir('/content/')
print('Enjoy! :)')

"""# (Load sample LAMDa CHORDS DATA file)"""

chords_data = TMIDIX.Tegridy_Any_Pickle_File_Reader('/content/CHORDS_DATA/LAMDa_CHORDS_DATA_2500')
print('Done!')

"""# (Decode to MIDI)"""

data = random.choice(chords_data)

file_name = data[0]
song = data[1]

song_f = []

time = 0
dur = 0
vel = 90
pitch = 0
channel = 0

patches = [-1] * 16

channels = [0] * 16
channels[9] = 1

for ss in song:

    time += ss[0] * 16

    for i in range(0, len(ss[1:]), 4):

        s = ss[1:][i:i+4]

        dur = s[0] * 16

        patch = s[1]

        if patch < 128:
            if patch not in patches:
                if 0 in channels:
                    cha = channels.index(0)
                    channels[cha] = 1
                else:
                    cha = 15
                patches[cha] = patch
                channel = patches.index(patch)
            else:
                channel = patches.index(patch)

        if patch == 128:
            channel = 9

        pitch = s[2]

        vel = s[3]

        song_f.append(['note', time, dur, channel, pitch, vel, patch ])

patches = [0 if x==-1 else x for x in patches]


detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
                                                        output_signature = file_name+'.mid',
                                                        output_file_name = '/content/Los-Angeles-MIDI-Dataset-Composition',
                                                        track_name='Project Los Angeles',
                                                        list_of_MIDI_patches=patches
                                                        )

"""# Congrats! You did it! :)"""