@@ -119,7 +119,7 @@ Returns 120 if not found.
119
119
function qpm (t:: MIDI.MIDIFile )
120
120
# META-event list:
121
121
tttttt = Vector {UInt32} ()
122
- # Find the one that corresponds to Set-Time :
122
+ # Find the one that corresponds to Set Tempo :
123
123
# The event tttttt corresponds to the command
124
124
# FF 51 03 tttttt Set Tempo (in microseconds per MIDI quarter-note)
125
125
# See here (page 8):
@@ -135,6 +135,8 @@ function qpm(t::MIDI.MIDIFile)
135
135
136
136
# Default QPM if it is not present in the MIDI file.
137
137
if isempty (tttttt)
138
+ @warn """ The Set Tempo event is not present in the given MIDI file.
139
+ A default value of 120.0 quarter notes per minute is returned."""
138
140
return 120.0
139
141
end
140
142
@@ -160,9 +162,7 @@ Returns QPM if not found.
160
162
"""
161
163
function bpm (t:: MIDI.MIDIFile )
162
164
QPM = qpm (t)
163
-
164
- # Default cc if not found
165
- cc = 24
165
+ cc = - 1
166
166
167
167
# Find the one that corresponds to Time Signature:
168
168
# FF 58 04 nn dd cc bb Time Signature
@@ -176,6 +176,14 @@ function bpm(t::MIDI.MIDIFile)
176
176
end
177
177
end
178
178
end
179
+
180
+ if cc == - 1
181
+ @warn """ The Time Signature event is not present in the given MIDI file.
182
+ A default value of 24 cc (clocks per metronome click) is used for calculating the BPM."""
183
+ # Default cc if not found
184
+ cc = 24
185
+ end
186
+
179
187
bpm = QPM * 24 / cc
180
188
end
181
189
@@ -208,6 +216,8 @@ function BPM(t::MIDI.MIDIFile)
208
216
209
217
# Default BPM if it is not present in the MIDI file.
210
218
if isempty (tttttt)
219
+ @warn """ The Set Tempo event is not present in the given MIDI file.
220
+ A default value of 120.0 quarter notes per minute is returned."""
211
221
return 120.0
212
222
end
213
223
@@ -246,6 +256,9 @@ function time_signature(t::MIDI.MIDIFile)
246
256
end
247
257
end
248
258
259
+ @warn """ The Time Signature event is not present in the given MIDI file.
260
+ A default value of 4/4 is returned."""
261
+
249
262
# Default time signature if it is not present in the file
250
263
return " 4/4"
251
264
end
@@ -259,7 +272,9 @@ Returns [(0, 120.0)] if there are no tempo events.
259
272
"""
260
273
function tempochanges (midi:: MIDIFile )
261
274
# Stores (position, tempo) pairs
262
- tempo_changes = [(0 , 120.0 )]
275
+ # Calls qpm() to store the first tempo value
276
+ # If there is no tempo event, qpm will warn and return 120.0
277
+ tempo_changes = [(0 , qpm (midi))]
263
278
position = 0
264
279
for event in midi. tracks[1 ]. events
265
280
position += event. dT
0 commit comments