Skip to content

Commit

Permalink
more convenient syntax for drumnotes
Browse files Browse the repository at this point in the history
Closes #125
  • Loading branch information
Datseris committed Feb 17, 2020
1 parent 27f3798 commit c67c5e9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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).
# v1.8.0
* `DrumNote` shorthand constructor, keyword constructor for `Note` and added `DRUMKEY` dictionary in constants.jl (originally in MusicVisualizations).
# v1.7.0
* Notes constructor allows values of `tpq` greater than `960`.
# v1.6.0
Expand Down
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name = "MIDI"
uuid = "f57c4921-e30c-5f49-b073-3f2f2ada663e"
repo = "https://github.com/JuliaMusic/MIDI.jl.git"
version = "1.7.1"
version = "1.8.0"

[compat]
julia = "1"


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

Expand Down
31 changes: 31 additions & 0 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,34 @@ const GM = Dict(
"Applause" => UInt8(127),
"Gunshot" => UInt8(128)
)

"""
DRUMKEY
A dictionary that given the drum instrument as a string it returns the
MIDI pitch that MuseScore uses. See
https://musescore.org/sites/musescore.org/files/General%20MIDI%20Standard%20Percussion%20Set%20Key%20Map.pdf
for a more complete list.
"""
const DRUMKEY = begin
a =
Dict(
"Acoustic Bass Drum" => "B1",
"Acoustic Snare" => "D2",
"Side Stick" => "C#2",
"Closed Hi-Hat" => "F#2",
"Open Hi-Hat" => "A#2",
"Pedal Hi-Hat" => "G#2",
"Ride Cymbal" => "D#3",
"Ride Bell" => "F3",
"Low-Mid Tom" => "B2",
"Cowbell" => "G#3",
"Tambourine" => "F#3",
"High Floor Tom" => "G2",
"Low Floor Tom" => "F2",
"Crash Cymbal 1" => "C#3",
"Crash Cymbal 2" => "A3"
)
end

export DRUMKEY
17 changes: 14 additions & 3 deletions src/note.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export Note, Notes, AbstractNote
export Note, Notes, AbstractNote, DrumNote
export pitch_to_name, name_to_pitch

abstract type AbstractNote end
Expand Down Expand Up @@ -47,9 +47,20 @@ Note(pitch, velocity, position, duration, channel)

@inline Note(n::Note) = n

import Base.==
"""
DrumNote(pitch, position, duration = 960; velocity = 100)
Shorthand constructor for a [`Note`](@ref) that is always on channel `9`.
It is possible to specify pitch as a `String` (e.g. "Acoustic Snare"), which
will be converted to actual pitch using [`DRUMKEY`](@ref).
"""
DrumNote(pitch, position, duration = 960; velocity = 100, gmmap = DRUMKEY) =
Note(_drumpitch(pitch, gmmap), velocity, position, duration, 9)

==(n1::Note, n2::Note) =
_drumpitch(pitch::Real, gmmap) = pitch
_drumpitch(pitch::String, gmmap) = name_to_pitch(gmmap[pitch])

import Base.==
==(n1::AbstractNote, n2::AbstractNote) =
n1.pitch == n2.pitch &&
n1.duration == n2.duration &&
n1.position == n2.position &&
Expand Down

2 comments on commit c67c5e9

@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/9657

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.8.0 -m "<description of version>" c67c5e976a406ac53f9a220d5c5f7479c38ca858
git push origin v1.8.0

Please sign in to comment.