-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIDISongProperties.ts
247 lines (223 loc) · 6.83 KB
/
MIDISongProperties.ts
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
MIDI-2-Text
A Musical Prompt Generator and Re-Orchestrator for the MIDI Standard Specification.
MIDI-2-Text library enables the generation and musical variation of prompts derived from MIDI files.
Re-Orchestration is facilitated by switching instruments within the same General MIDI InstrumentGroups as well as modulating tempo and dynamics.
getSongPrompt has the following modes and parameters:
1. Re-Orchestration Mode: If == 1, then re-orchestrate the song's instruments to similar instruments.
2. Tempo-Scalar: Modulates the song prompt's tempo description.
3. Dynamic-Scalar: Modulates the description of the song's dynamics.
*/
import { GeneralMIDIInstruments } from "./MIDI_Instruments"
import { Dynamic_Markings } from "./Music/DynamicMarking"
import { note_keys } from "./Music/Modes"
import { PitchClass } from "./Music/PitchClass"
import { Tempo_Markings } from "./Music/TempoMarking"
import {
DEFAULTBEATDIVISION,
DEFAULTKEY,
DEFAULTNUMBEATS,
DEFAULTQUALITY,
DEFAULTSONGADDRESS,
DEFAULTTEMPO,
DEFAULTVELOCITY,
DOWNTRANS,
MAXTEMPO,
MINTEMPO,
UPTRANS,
} from "./Consts"
export class MIDISongProperties {
address: string
name: string
tonic: PitchClass //key might end up stored as MIDI or JSON instead of tonic+ quality
quality: number
minTempo: number
maxTempo: number
downTrans: number
upTrans: number
defaulttempo: number
defaultbeatdivision: number
defaultnumberofbeats: number
defaultvelocity: number
textdescription: string
instruments: string[]
constructor(
address?: string,
name?: string,
tonic?: PitchClass,
quality?: number,
minTempo?: number,
maxTempo?: number,
downTrans?: number,
defaulttempo?: number,
defaultbeatdivision?: number,
defaultnumberofbeats?: number,
defaultvelocity?: number,
upTrans?: number,
textdescription?: string,
instruments?: string[]
) {
this.address = address || DEFAULTSONGADDRESS
this.name = name || "FireLily"
this.tonic = tonic || DEFAULTKEY //key might end up stored as MIDI or JSON instead of tonic + quality
this.quality = quality || DEFAULTQUALITY
this.minTempo = minTempo || MINTEMPO
this.maxTempo = maxTempo || MAXTEMPO
this.downTrans = downTrans || DOWNTRANS
this.upTrans = upTrans || UPTRANS
this.defaulttempo = defaulttempo || DEFAULTTEMPO
this.defaultnumberofbeats = defaultnumberofbeats || DEFAULTNUMBEATS
this.defaultbeatdivision = defaultbeatdivision || DEFAULTBEATDIVISION
this.defaultvelocity = defaultvelocity || DEFAULTVELOCITY
this.textdescription = textdescription || "baroque"
this.instruments = instruments || ["Flute", "Contrabass", "Harpsichord"]
}
reorchestrateInstruments() {
let outlist: string[] = []
let insts = new GeneralMIDIInstruments()
for (let i = 0; i < this.instruments.length; i++) {
outlist.push(insts.getAnotherInstrumentInCategory(this.instruments[i]))
}
return outlist
}
/*
console.log(getInstrumentPrompt(["Flute", "Acoustic Guitar", "Violin"])) ->
" Flute, Acoustic Guitar, & Violin."
if mode = 1, reorchestrate Instruments
*/
getInstrumentPrompt(reorchestrate_mode: number) {
let intlist: string[] = []
if (reorchestrate_mode == 1) {
intlist = this.reorchestrateInstruments()
} else {
intlist = this.instruments
}
let prompt = ""
for (let i = 0; i < intlist.length; i++) {
if (i == intlist.length - 1) {
if (intlist.length > 1) {
prompt += " and "
}
prompt += intlist[i] //+ "."
} else {
prompt += " " + intlist[i]
if (i < intlist.length - 2) {
prompt += ","
}
}
}
return prompt
}
// mode - If == 1, Reorchestrate instruments
// Tempo/Dynamic Scale
getSongPrompt(
reorchestrate_mode: number,
temposcale: number,
dynamicscale: number
) {
let updatedtempo = Math.trunc(this.defaulttempo * temposcale)
let updatedvelocity = Math.trunc(this.defaultvelocity * dynamicscale)
let tempomarking = new Tempo_Markings()
let dynamicmarking = new Dynamic_Markings()
let instp: string
if (reorchestrate_mode == 1) {
instp = this.getInstrumentPrompt(reorchestrate_mode)
} else {
instp = this.getInstrumentPrompt(reorchestrate_mode)
}
// let tempo_marker = getTempoMarkingText(this.defaulttempo)
let dynamic_marker = dynamicmarking.getVelocityMarkingName(updatedvelocity)
let key = note_keys[this.tonic.note]
let mode: string = ""
if (this.quality == 0) {
mode = "major"
} else {
mode = "minor"
}
let quality = note_keys[this.tonic.note]
return (
"A " +
this.textdescription +
" " +
dynamic_marker +
" song named " +
this.name +
" in the key of " +
key +
" " +
mode +
" played by " +
dynamicmarking.getVelocityMarking(updatedvelocity) +
instp +
// tempomarking.getTempoMarkingName(this.defaulttempo) +
" " +
tempomarking.getTempoMarking(updatedtempo) +
", " +
updatedtempo +
" BPM" +
" in " +
this.defaultnumberofbeats +
"/" +
this.defaultbeatdivision +
" time" +
"."
)
}
getMidJourneySongPrompt(
reorchestrate_mode: number,
temposcale: number,
dynamicscale: number
) {
let updatedtempo = Math.trunc(this.defaulttempo * temposcale)
let updatedvelocity = Math.trunc(this.defaultvelocity * dynamicscale)
let tempomarking = new Tempo_Markings()
let dynamicmarking = new Dynamic_Markings()
let instp: string
if (reorchestrate_mode == 1) {
instp = this.getInstrumentPrompt(reorchestrate_mode)
} else {
instp = this.getInstrumentPrompt(reorchestrate_mode)
}
// let tempo_marker = getTempoMarkingText(this.defaulttempo)
let dynamic_marker = dynamicmarking.getVelocityMarkingName(updatedvelocity)
let key = note_keys[this.tonic.note]
let mode: string = ""
if (this.quality == 0) {
mode = "major"
} else {
mode = "minor"
}
let quality = note_keys[this.tonic.note]
let mid_journey_intro =
" Double exposure, with fantasy landscape of castles and rivers and war. "
let mid_journey_outro = " --v 4 --q 2"
return (
mid_journey_intro +
" A " +
this.textdescription +
" " +
dynamic_marker +
" song named " +
this.name +
" in the key of " +
key +
" " +
mode +
" played by " +
dynamicmarking.getVelocityMarking(updatedvelocity) +
instp +
// tempomarking.getTempoMarkingName(this.defaulttempo) +
" " +
tempomarking.getTempoMarking(updatedtempo) +
", " +
updatedtempo +
" BPM" +
" in " +
this.defaultnumberofbeats +
"/" +
this.defaultbeatdivision +
" time" +
"." + mid_journey_outro
)
}
}