Skip to content

Commit

Permalink
Merge pull request #23 from ZaneH/wip-fix-midi
Browse files Browse the repository at this point in the history
Attempt to improve MIDI handling
  • Loading branch information
ZaneH committed Jul 24, 2024
2 parents a7613fc + a17d7e9 commit 5c7e329
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 76 deletions.
91 changes: 22 additions & 69 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tauri-build = { version = "1.5.3", features = [] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.8", features = [ "updater", "api-all"] }
midir = "0.10.0"
midir = "0.8.0"
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }

[dependencies.sentry-tauri]
Expand Down
10 changes: 7 additions & 3 deletions src/components/Keyboard/Keyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ const Keyboard = () => {

listen('midi_message', (event) => {
const payload = event.payload as { message: number[] }
const [command, note, velocity] = payload.message
const [status, note, velocity] = payload.message

if (command === 144 || command === 155) {
const command = status & 0xf0

if (command === 0x90) {
// Note on
setActiveNotes((an) => ({
...an,
[note]: true,
Expand All @@ -89,7 +92,8 @@ const Keyboard = () => {

// some midi keyboards don't send the off signal,
// they just set the velocity to 0
if (command === 128 || command === 139 || velocity === 0) {
if (command === 0x80 || velocity === 0) {
// Note off
setActiveNotes((an) => ({
...an,
[note]: false,
Expand Down
10 changes: 7 additions & 3 deletions src/components/Quiz/Quiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,21 @@ const Quiz = () => {

listen('midi_message', (event) => {
const payload = event.payload as { message: number[] }
const [command, note, velocity] = payload.message
const [status, note, velocity] = payload.message

if (command === 144 || command === 155) {
const command = status & 0xf0

if (command === 0x90) {
// Note off
setChordStack?.((cs) => [...cs, note])
setActiveNotes((an) => ({
...an,
[note]: true,
}))
}

if (command === 128 || command === 139 || velocity === 0) {
if (command === 0x80 || velocity === 0) {
// Note on
// remove midiNumber from chordStack
setChordStack?.((cs) => {
const removalIdx = cs.indexOf(note)
Expand Down

0 comments on commit 5c7e329

Please sign in to comment.