Skip to content

Commit 730ef3a

Browse files
Add warnings for default value functions (#139)
* Add default value warnings for functions * Update bug_report.md * Update Project.toml
1 parent b80dad1 commit 730ef3a

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Please provide a piece of code that leads to the bug you encounter.
1515

1616
If the code is **runnable**, it will help us identify the problem faster.
1717

18-
**Agents.jl version**
18+
**MIDI.jl version**
1919

20-
Please provide the version you use (you can do `Pkg.status("Agents")`.
20+
Please provide the version you use (you can do `Pkg.status("MIDI")`.

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MIDI"
22
uuid = "f57c4921-e30c-5f49-b073-3f2f2ada663e"
33
repo = "https://github.com/JuliaMusic/MIDI.jl.git"
4-
version = "1.12.2"
4+
version = "1.12.3"
55

66
[compat]
77
julia = "1"

src/midifile.jl

+20-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Returns 120 if not found.
119119
function qpm(t::MIDI.MIDIFile)
120120
# META-event list:
121121
tttttt = Vector{UInt32}()
122-
# Find the one that corresponds to Set-Time:
122+
# Find the one that corresponds to Set Tempo:
123123
# The event tttttt corresponds to the command
124124
# FF 51 03 tttttt Set Tempo (in microseconds per MIDI quarter-note)
125125
# See here (page 8):
@@ -135,6 +135,8 @@ function qpm(t::MIDI.MIDIFile)
135135

136136
# Default QPM if it is not present in the MIDI file.
137137
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."""
138140
return 120.0
139141
end
140142

@@ -160,9 +162,7 @@ Returns QPM if not found.
160162
"""
161163
function bpm(t::MIDI.MIDIFile)
162164
QPM = qpm(t)
163-
164-
# Default cc if not found
165-
cc = 24
165+
cc = -1
166166

167167
# Find the one that corresponds to Time Signature:
168168
# FF 58 04 nn dd cc bb Time Signature
@@ -176,6 +176,14 @@ function bpm(t::MIDI.MIDIFile)
176176
end
177177
end
178178
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+
179187
bpm = QPM * 24 / cc
180188
end
181189

@@ -208,6 +216,8 @@ function BPM(t::MIDI.MIDIFile)
208216

209217
# Default BPM if it is not present in the MIDI file.
210218
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."""
211221
return 120.0
212222
end
213223

@@ -246,6 +256,9 @@ function time_signature(t::MIDI.MIDIFile)
246256
end
247257
end
248258

259+
@warn """The Time Signature event is not present in the given MIDI file.
260+
A default value of 4/4 is returned."""
261+
249262
# Default time signature if it is not present in the file
250263
return "4/4"
251264
end
@@ -259,7 +272,9 @@ Returns [(0, 120.0)] if there are no tempo events.
259272
"""
260273
function tempochanges(midi::MIDIFile)
261274
# 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))]
263278
position = 0
264279
for event in midi.tracks[1].events
265280
position += event.dT

0 commit comments

Comments
 (0)