-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get MIDI input working to label pressed keys
This needs refactoring, but again, it's working!
- Loading branch information
1 parent
960274b
commit 19aadda
Showing
5 changed files
with
119 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const std = @import("std"); | ||
const rtmidi = @import("rtmidi"); | ||
|
||
pub const MidiInput = struct { | ||
midi_in: *rtmidi.In, | ||
callback_fn: ?*const fn (f64, []const u8, ?*anyopaque) void, | ||
|
||
pub fn init() !MidiInput { | ||
var midi_in = rtmidi.In.createDefault() orelse return error.MidiInCreateFailed; | ||
errdefer midi_in.destroy(); | ||
|
||
return MidiInput{ | ||
.midi_in = midi_in, | ||
.callback_fn = null, | ||
}; | ||
} | ||
|
||
pub fn deinit(self: *MidiInput) void { | ||
self.midi_in.destroy(); | ||
} | ||
|
||
pub fn openPort(self: *MidiInput, port: usize, port_name: [:0]const u8) !void { | ||
self.midi_in.openPort(port, port_name); | ||
} | ||
|
||
pub fn setCallback(self: *MidiInput, comptime callback: fn (f64, []const u8, ?*anyopaque) void, user_data: ?*anyopaque) void { | ||
self.callback_fn = callback; | ||
self.midi_in.setCallback(callback, user_data); | ||
} | ||
|
||
pub fn cancelCallback(self: *MidiInput) void { | ||
self.midi_in.cancelCallback(); | ||
self.callback_fn = null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
const std = @import("std"); | ||
const rtmidi = @import("rtmidi"); | ||
|
||
pub const MidiOutput = struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters