Skip to content

Commit

Permalink
cleanup a few things (#148)
Browse files Browse the repository at this point in the history
* moved exports and usings to MIDI.jl
* removed nonexistent exports for textevent and decode
* removed unnecesary type param on show methods
  • Loading branch information
anandijain authored Sep 18, 2021
1 parent 3125b5a commit c827fdd
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.jl.cov
*.jl.mem
Manifest.toml
19 changes: 18 additions & 1 deletion src/MIDI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ A Julia library for reading and writing MIDI files.
"""
module MIDI

using FileIO
using Base.Unicode

include("constants.jl")
include("note.jl")
include("trackevent.jl")
Expand All @@ -15,8 +18,22 @@ include("convert.jl")
include("findevents.jl")
include("deprecations.jl")


export testmidi, testnotes
export DRUMKEY
export type1totype0, type1totype0!
export type0totype1, type0totype1!
export getprogramchangeevents
export encode
export trackname, addtrackname!, findtextevents
export tracknames
export MIDIFile, readMIDIFile, writeMIDIFile
export BPM, bpm, qpm, time_signature, tempochanges, ms_per_tick
export getnotes, addnote!, addnotes!, addevent!, addevents!
export MIDITrack
export Note, Notes, AbstractNote, DrumNote
export pitch_to_name, name_to_pitch
export TrackEvent, MetaEvent, MIDIEvent, SysexEvent
export readvariablelength, writevariablelength

"""
testmidi()
Expand Down
2 changes: 0 additions & 2 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,3 @@ const DRUMKEY = begin
"Crash Cymbal 2" => "A3"
)
end

export DRUMKEY
4 changes: 0 additions & 4 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ function type1totype0(data::MIDIFile)
type1totype0!(newdata)
end

export type1totype0, type1totype0!

function type0totype1!(data::MIDIFile)
if data.format != UInt8(0)
error("Got type $(data.format); expecting type 0")
Expand Down Expand Up @@ -64,7 +62,6 @@ function type0totype1(data::MIDIFile)
type0totype1!(newdata)
end

export type0totype1, type0totype1!

function insertsorted!(events1::Array{TrackEvent, 1},
events2::Array{TrackEvent, 1})
Expand Down Expand Up @@ -115,7 +112,6 @@ function getprogramchangeevents(data::MIDIFile)
end
pgevents
end
export getprogramchangeevents

function dochannelsconflict(pgevents)
channels = Dict()
Expand Down
2 changes: 0 additions & 2 deletions src/events.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export encode, decode

# Create a map from typebyte to the type definitions (not the actual types)
const MIDI_EVENTS_DEFS = Dict(
# MetaEvents
Expand Down
3 changes: 0 additions & 3 deletions src/findevents.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Functions that find special events, like e.g. lyrics, or tracknames
# are contained here

export trackname, addtrackname!, textevent, findtextevents
export tracknames

const NOTRACKNAME = "No track name found"

"""
Expand Down
2 changes: 0 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using FileIO

"""
load(filename::File{format"MIDI"})
Read a file into a `MIDIFile` data type.
Expand Down
5 changes: 1 addition & 4 deletions src/midifile.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export MIDIFile, readMIDIFile, writeMIDIFile
export BPM, bpm, qpm, time_signature, tempochanges, ms_per_tick

"""
MIDIFile <: Any
Type representing a file of MIDI data.
Expand All @@ -16,7 +13,7 @@ mutable struct MIDIFile
tracks::Vector{MIDITrack}
end
# Pretty print
function Base.show(io::IO, midi::MIDIFile) where {N}
function Base.show(io::IO, midi::MIDIFile)
tnames = tracknames(midi)
s = "MIDIFile (format=$(Int(midi.format)), tpq=$(midi.tpq)) "
if any(!isequal(NOTRACKNAME), tnames) # we have tracknames
Expand Down
5 changes: 1 addition & 4 deletions src/miditrack.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export getnotes, addnote!, addnotes!, addevent!, addevents!
export MIDITrack

"""
MIDITrack <: Any
Expand All @@ -16,7 +13,7 @@ mutable struct MIDITrack
end
MIDITrack() = MIDITrack(TrackEvent[])
# Pretty print
function Base.show(io::IO, t::MIDITrack) where {N}
function Base.show(io::IO, t::MIDITrack)
L = length(t.events)
M = count(x -> x isa MIDIEvent, t.events)
T = count(x -> x isa MetaEvent, t.events)
Expand Down
4 changes: 0 additions & 4 deletions src/note.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export Note, Notes, AbstractNote, DrumNote
export pitch_to_name, name_to_pitch

abstract type AbstractNote end

"""
Expand Down Expand Up @@ -119,7 +116,6 @@ Base.copy(notes::Notes) = Notes([copy(n) for n in notes], notes.tpq)
#######################################################
# string name <-> midi pitch
#######################################################
using Base.Unicode
const PITCH_TO_NAME = Dict(
0=>"C", 1=>"C♯", 2=>"D", 3=>"D♯", 4=>"E", 5=>"F", 6=>"F♯", 7=>"G", 8=>"G♯", 9=>"A",
10 =>"A♯", 11=>"B")
Expand Down
2 changes: 0 additions & 2 deletions src/trackevent.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export TrackEvent, MetaEvent, MIDIEvent, SysexEvent

"""
TrackEvent <: Any
Abstract supertype for all MIDI events.
Expand Down
1 change: 0 additions & 1 deletion src/variablelength.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export readvariablelength, writevariablelength
"""
readvariablelength(f::IO)
Variable length numbers in MIDI files are represented as a sequence of bytes.
Expand Down

0 comments on commit c827fdd

Please sign in to comment.