Skip to content

Commit

Permalink
fix id 0-based bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenPL authored Jan 22, 2024
1 parent 7625aba commit 313c151
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/src/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ We can use the free program [loopMIDI](https://www.tobias-erichsen.de/software/l
- Create a new MIDI channel called `loopMIDI Port` and click the `+` button.

#### Finding an existing MIDI channel with PortMIDI
After the MIDI channel is created, we just need to obtain its ID.
After the MIDI channel is created, we just need to obtain its ID. Note that the ID index is 0-based.
_Important note: The first call of `Pm_Initialize()` needs to happen after the MIDI channel was created. Alternatively, one needs to call `Pm_Terminate()` first before `Pm_Initialize()` to obtain the correct list of current channels._

The following code uses the `Pm_GetDeviceInfo` function which returns a C pointer to a `PmDeviceInfo` which has inparticular a `name` and `output` field, which we check to get the right channel.
Expand All @@ -79,7 +79,7 @@ using PortMIDI

Pm_Initialize()

id = findfirst(x -> unsafe_string(x.name) == "loopMIDI Port" && x.output > 0, (unsafe_load(Pm_GetDeviceInfo(i)) for i in 0:Pm_CountDevices()-1))
id = findfirst(x -> unsafe_string(x.name) == "loopMIDI Port" && x.output > 0, (unsafe_load(Pm_GetDeviceInfo(i)) for i in 0:Pm_CountDevices()-1))-1

if isnothing(id)
error("Could not find MIDI channel 'loopMIDI Port'.")
Expand Down Expand Up @@ -143,4 +143,4 @@ Afterwards, we should close the MIDI stream and terminate PortMidi:
```julia
Pm_Close(stream[])
Pm_Terminate()
```
```

0 comments on commit 313c151

Please sign in to comment.