Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SequencerSpecificEvent , and empty!(::MIDITrack) #173

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).
# v2.7.0
* New event type `SequencerSpecificEvent`.
NeroBlackstone marked this conversation as resolved.
Show resolved Hide resolved
# v2.6.0
* New functions `metric_time`.
* New functions `duration_metric_time`.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"

[compat]
FileIO = "1"
IterTools = "1.8.0"
IterTools = "1.10.0"
NeroBlackstone marked this conversation as resolved.
Show resolved Hide resolved
julia = "1"

[extras]
Expand Down
31 changes: 24 additions & 7 deletions src/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ const MIDI_EVENTS_DEFS = Dict(
decode = :(Int.(data)),
encode = :(UInt8.([event.semitones, event.scale]))
),

0x7f => (
type = :SequencerSpecificEvent,
fields = ["ssdata::Vector{UInt8}"],
decode = :(data),
encode = :(event.ssdata)
),
# MidiEvents
0x80 => (
type = :NoteOffEvent,
Expand Down Expand Up @@ -124,12 +129,14 @@ function define_type(type, fields, decode, encode_, supertype, typebyte)
$(fields...)
end

""" $($type)(dT::Int, typebyte::UInt8, data::Vector{UInt8})
Returns a `$($type)` event from it's byte representation.
The parameter `typebyte::UInt8` is its's $(($type <: MetaEvent) ? "metatype" : "status") byte.
"""
function $type(dT::Int, typebyte::UInt8, data::Vector{UInt8})
$type(dT, typebyte, $decode...)
if !($type.types[end] <: AbstractArray)
""" $($type)(dT::Int, typebyte::UInt8, data::Vector{UInt8})
Returns a `$($type)` event from it's byte representation.
The parameter `typebyte::UInt8` is its's $(($type <: MetaEvent) ? "metatype" : "status") byte.
"""
function $type(dT::Int, typebyte::UInt8, data::Vector{UInt8})
$type(dT, typebyte, $decode...)
end
end

if $type <: MetaEvent
Expand Down Expand Up @@ -407,3 +414,13 @@ The `PitchBendEvent` informs a MIDI device to modify the pitch in a specific cha
* `pitch::Int` : Value of the pitch bend.
"""
PitchBendEvent

""" SequencerSpecificEvent <: MetaEvent
The `SequencerSpecificEvent` is used to store vendor-proprietary data in a MIDI file.

## Fields:
* `dT::Int` : Delta time in ticks.
* `metatype::UInt8` : Meta type byte of the event.
* `ssdata::Vector{UInt8}` : Vendor-proprietary data.
"""
SequencerSpecificEvent
Binary file added test/SequencerSpecific.mid
NeroBlackstone marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
8 changes: 8 additions & 0 deletions test/metaevent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@
@test_throws errtype MIDI.readsysexevent(Int(input[1]), IOBuffer(input[2:length(input)]))
end
end

@testset "SequencerSpecificEvent" begin
midi = load("SequencerSpecific.mid")
Copy link
Member

Choose a reason for hiding this comment

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

i don't undertstand what you are doing here. You are loading this midi data, but you don't use them next in the test suite...? The current test suite is meaningless you are only testing whether you initialized the SequencerSpecificEvent with the values you initialized it with. Rather trivial, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I don't think it's necessary to actually use this midi data.
If the added code is incorrect, an error will be throwed on this line when initialization, and causing the test to fail.
The fact that no exception is thrown already indicates that SequencerSpecificEvent is being parsed and instantiated correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests have been added

Copy link
Member

Choose a reason for hiding this comment

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

What, no not at all. What we want to know is whether we correctly find this special midi type in an actual midi track that we load. Instantiating the type is trivial, you aren't testing anything really if you only test that.

Copy link
Member

Choose a reason for hiding this comment

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

But now we have this midi file, and it is very small, so thank you, this is exactly what I was asking for!

@test length(getnotes(midi.tracks[1], midi.tpq)) > 0

sse = MIDI.SequencerSpecificEvent(0, 0x7f, [0x11, 0x21, 0x53, 0x1F])
@test sse.ssdata == [0x11, 0x21, 0x53, 0x1F]
end
end