Skip to content

Commit

Permalink
improve printing of MIDI by showing tracks
Browse files Browse the repository at this point in the history
Closes #118
  • Loading branch information
Datseris committed Nov 5, 2019
1 parent d564666 commit a9ac7b7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

# master
# v1.5.0
* `show` for midi now states the contained tracks

# v1.4.0
* Added convenience function `tracknames(midi)`

Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = "MIDI"
uuid = "f57c4921-e30c-5f49-b073-3f2f2ada663e"
repo = "https://github.com/JuliaMusic/MIDI.jl.git"
version = "1.4.3"
version = "1.5.0"

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
julia = "≥ 0.7.0"
julia = "1"
8 changes: 6 additions & 2 deletions src/findevents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
export trackname, addtrackname!, textevent, findtextevents
export tracknames

const NOTRACKNAME = "No track name found"

"""
trackname(track::MIDI.MIDITrack)
Return the name of the given `track` as a string,
by finding the "track name" `MetaEvent`.
If no such event exists, `"No track name found"` is returned.
"""
function trackname(track::MIDI.MIDITrack)

pos = findtrackname(track)
if pos == 0
return "No track name found"
return NOTRACKNAME
# check if there really is a name
elseif length(track.events[pos].data) == 0
return "No track name found"
return NOTRACKNAME
else
event = track.events[pos]
# extract the name (string(Char()) takes care of ASCII encoding)
Expand Down
14 changes: 11 additions & 3 deletions src/midifile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ mutable struct MIDIFile
end
# Pretty print
function Base.show(io::IO, midi::MIDIFile) where {N}
print(io, "MIDIFile:\n"*
" format: $(Int(midi.format))\n tracks: $(length(midi.tracks))\n"*
" tpq: $(midi.tpq)")
tnames = tracknames(midi)
s = "MIDIFile (format=$(Int(midi.format)), tpq=$(midi.tpq)) "
if any(!isequal(NOTRACKNAME), tnames) # we have tracknames
s *= "with tracks:\n"
for t in tnames
s *= " "*t*"\n"
end
else # some track doesn't have a name
s *= "with $(length(midi.tracks)) tracks"
end
print(io, s)
end


Expand Down

2 comments on commit a9ac7b7

@Datseris
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/5100

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.0 -m "<description of version>" a9ac7b7b62f60519d8cbe635007624fb3fdd54a0
git push origin v1.5.0

Please sign in to comment.