misnaej commited on
Commit
d08186b
1 Parent(s): 6cc2135

changed instrument mapping

Browse files
Files changed (4) hide show
  1. .vscode/settings.json +3 -0
  2. constants.py +58 -14
  3. load.py +2 -2
  4. playground.py +11 -9
.vscode/settings.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "python.formatting.provider": "black"
3
+ }
constants.py CHANGED
@@ -24,54 +24,98 @@ INSTRUMENT_CLASSES = [
24
  INSTRUMENT_TRANSFER_CLASSES = [
25
  {
26
  "name": "Piano",
27
- "program_range": [4], # Electric Piano 1
28
  "family_number": 0,
 
29
  },
30
  {
31
  "name": "Chromatic Percussion",
32
- "program_range": [11], # Vibraphone
33
  "family_number": 1,
 
 
 
 
 
 
 
34
  },
35
- {"name": "Organ", "program_range": [17], "family_number": 2}, # Percussive Organ
36
  {
37
  "name": "Guitar",
38
- "program_range": [80], # Synth Lead Square
39
  "family_number": 3,
 
40
  },
41
  {
42
  "name": "Bass",
43
- "program_range": [38], # Synth bass 1,
44
  "family_number": 4,
 
45
  },
46
  {
47
  "name": "Strings",
48
- "program_range": [50], # Synth Strings 1
49
  "family_number": 5,
 
50
  },
51
  {
52
  "name": "Ensemble",
53
- "program_range": [51], # Synth Strings 2
54
  "family_number": 6,
 
55
  },
56
  {
57
  "name": "Brass",
58
- "program_range": [63], # 63 Synth Brass 1,
59
  "family_number": 7,
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  },
61
- {"name": "Reed", "program_range": [64], "family_number": 8}, # Synth Brass 2
62
- {"name": "Pipe", "program_range": [82], "family_number": 9}, # Lead 3
63
  {
64
  "name": "Synth Lead",
65
  "program_range": [81], # Synth Lead Sawtooth
66
  "family_number": 10,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  },
68
- {"name": "Synth Pad", "program_range": range(88, 96), "family_number": 11},
69
- {"name": "Synth Effects", "program_range": range(96, 104), "family_number": 12},
70
- {"name": "Ethnic", "program_range": range(104, 112), "family_number": 13},
71
- {"name": "Percussive", "program_range": range(112, 120), "family_number": 14},
72
  {
73
  "name": "Sound Effects",
74
  "program_range": range(120, 128),
75
  "family_number": 15,
 
76
  },
77
  ]
 
24
  INSTRUMENT_TRANSFER_CLASSES = [
25
  {
26
  "name": "Piano",
27
+ "program_range": [4],
28
  "family_number": 0,
29
+ "transfer_to": "Electric Piano 1",
30
  },
31
  {
32
  "name": "Chromatic Percussion",
33
+ "program_range": [11],
34
  "family_number": 1,
35
+ "transfer_to": "Vibraphone",
36
+ },
37
+ {
38
+ "name": "Organ",
39
+ "program_range": [17],
40
+ "family_number": 2,
41
+ "transfer_to": "Percussive Organ",
42
  },
 
43
  {
44
  "name": "Guitar",
45
+ "program_range": [80],
46
  "family_number": 3,
47
+ "transfer_to": "Synth Lead Square",
48
  },
49
  {
50
  "name": "Bass",
51
+ "program_range": [38],
52
  "family_number": 4,
53
+ "transfer_to": "Synth Bass 1",
54
  },
55
  {
56
  "name": "Strings",
57
+ "program_range": [50],
58
  "family_number": 5,
59
+ "transfer_to": "Synth Strings 1",
60
  },
61
  {
62
  "name": "Ensemble",
63
+ "program_range": [51],
64
  "family_number": 6,
65
+ "transfer_to": "Synth Strings 2",
66
  },
67
  {
68
  "name": "Brass",
69
+ "program_range": [63],
70
  "family_number": 7,
71
+ "transfer_to": "Synth Brass 1",
72
+ },
73
+ {
74
+ "name": "Reed",
75
+ "program_range": [64],
76
+ "family_number": 8,
77
+ "transfer_to": "Synth Brass 2",
78
+ },
79
+ {
80
+ "name": "Pipe",
81
+ "program_range": [82],
82
+ "family_number": 9,
83
+ "transfer_to": "Synth Lead Calliope",
84
  },
 
 
85
  {
86
  "name": "Synth Lead",
87
  "program_range": [81], # Synth Lead Sawtooth
88
  "family_number": 10,
89
+ "transfer_to": "Synth Lead Sawtooth",
90
+ },
91
+ {
92
+ "name": "Synth Pad",
93
+ "program_range": range(88, 96),
94
+ "family_number": 11,
95
+ "transfer_to": "Synth Pad",
96
+ },
97
+ {
98
+ "name": "Synth Effects",
99
+ "program_range": range(96, 104),
100
+ "family_number": 12,
101
+ "transfer_to": "Synth Effects",
102
+ },
103
+ {
104
+ "name": "Ethnic",
105
+ "program_range": range(104, 112),
106
+ "family_number": 13,
107
+ "transfer_to": "Ethnic",
108
+ },
109
+ {
110
+ "name": "Percussive",
111
+ "program_range": range(112, 120),
112
+ "family_number": 14,
113
+ "transfer_to": "Percussive",
114
  },
 
 
 
 
115
  {
116
  "name": "Sound Effects",
117
  "program_range": range(120, 128),
118
  "family_number": 15,
119
+ "transfer_to": "Sound Effects",
120
  },
121
  ]
load.py CHANGED
@@ -40,11 +40,11 @@ class LoadModel:
40
 
41
  def load_model(self):
42
  if self.revision is None:
43
- model = GPT2LMHeadModel.from_pretrained(self.path).to(self.device)
44
  else:
45
  model = GPT2LMHeadModel.from_pretrained(
46
  self.path, revision=self.revision
47
- ).to(self.device)
48
 
49
  return model
50
 
 
40
 
41
  def load_model(self):
42
  if self.revision is None:
43
+ model = GPT2LMHeadModel.from_pretrained(self.path) # .to(self.device)
44
  else:
45
  model = GPT2LMHeadModel.from_pretrained(
46
  self.path, revision=self.revision
47
+ ) # .to(self.device)
48
 
49
  return model
50
 
playground.py CHANGED
@@ -1,7 +1,8 @@
 
1
  import gradio as gr
2
  from load import LoadModel
3
  from generate import GenerateMidiText
4
- from constants import INSTRUMENT_CLASSES
5
  from decoder import TextDecoder
6
  from utils import get_miditok, index_has_substring
7
  from playback import get_music
@@ -12,7 +13,6 @@ from generation_utils import plot_piano_roll
12
  import numpy as np
13
 
14
  matplotlib.use("Agg")
15
- import matplotlib.pyplot as plt
16
 
17
  sys.modules["pylab"] = pylab
18
 
@@ -53,7 +53,11 @@ def generator(
53
  genesis = GenerateMidiText(model, tokenizer, piece_by_track)
54
  track = {"label": label}
55
  inst = next(
56
- (inst for inst in INSTRUMENT_CLASSES if inst["name"] == instrument),
 
 
 
 
57
  {"family_number": "DRUMS"},
58
  )["family_number"]
59
 
@@ -114,7 +118,8 @@ def instrument_row(default_inst, row_id):
114
  row = gr.Variable(row_id)
115
  with gr.Column(scale=1, min_width=50):
116
  inst = gr.Dropdown(
117
- [inst["name"] for inst in INSTRUMENT_CLASSES] + ["Drums"],
 
118
  value=default_inst,
119
  label="Instrument",
120
  )
@@ -150,16 +155,13 @@ with gr.Blocks() as demo:
150
  mixed_audio = gr.Audio(label="Mixed Audio")
151
  piano_roll = gr.Plot(label="Piano Roll")
152
  instrument_row("Drums", 0)
153
- instrument_row("Bass", 1)
154
- instrument_row("Synth Lead", 2)
155
  # instrument_row("Piano")
156
 
157
  demo.launch(debug=True)
158
 
159
  """
160
- TODO: DEPLOY
161
- TODO: temp file situation
162
- TODO: clear cache situation
163
  TODO: reset button
164
  TODO: add a button to save the generated midi
165
  TODO: add improvise button
 
1
+ import matplotlib.pyplot as plt
2
  import gradio as gr
3
  from load import LoadModel
4
  from generate import GenerateMidiText
5
+ from constants import INSTRUMENT_CLASSES, INSTRUMENT_TRANSFER_CLASSES
6
  from decoder import TextDecoder
7
  from utils import get_miditok, index_has_substring
8
  from playback import get_music
 
13
  import numpy as np
14
 
15
  matplotlib.use("Agg")
 
16
 
17
  sys.modules["pylab"] = pylab
18
 
 
53
  genesis = GenerateMidiText(model, tokenizer, piece_by_track)
54
  track = {"label": label}
55
  inst = next(
56
+ (
57
+ inst
58
+ for inst in INSTRUMENT_TRANSFER_CLASSES
59
+ if inst["transfer_to"] == instrument
60
+ ),
61
  {"family_number": "DRUMS"},
62
  )["family_number"]
63
 
 
118
  row = gr.Variable(row_id)
119
  with gr.Column(scale=1, min_width=50):
120
  inst = gr.Dropdown(
121
+ [inst["transfer_to"] for inst in INSTRUMENT_TRANSFER_CLASSES]
122
+ + ["Drums"],
123
  value=default_inst,
124
  label="Instrument",
125
  )
 
155
  mixed_audio = gr.Audio(label="Mixed Audio")
156
  piano_roll = gr.Plot(label="Piano Roll")
157
  instrument_row("Drums", 0)
158
+ instrument_row("Synth Bass 1", 1)
159
+ instrument_row("Synth Lead Square", 2)
160
  # instrument_row("Piano")
161
 
162
  demo.launch(debug=True)
163
 
164
  """
 
 
 
165
  TODO: reset button
166
  TODO: add a button to save the generated midi
167
  TODO: add improvise button