# Themidibus + python

**URL:** <https://discourse.processing.org/t/themidibus-python/10382>\
**Category:** Processing.py\
**Created:** [April 17, 2019, 8:32am UTC](https://discourse.processing.org/t/themidibus-python/10382 "2019-04-17T08:32:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lnp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lnp/32/4911_2.png) [@lnp](https://discourse.processing.org/u/lnp)\
**Post date:** [April 17, 2019, 8:32am UTC](https://discourse.processing.org/t/themidibus-python/10382/1 "2019-04-17T08:32:01Z")

</div>

Hi everyone —

I converted this java sample of themidibus in to python: [https://github.com/sparks/themidibus/blob/master/examples/Basic/Basic.pde](https://github.com/sparks/themidibus/blob/master/examples/Basic/Basic.pde)

I first made sure it worked with my midi device connected and responded in the java sample.

No technical issues in retooling the code but it won’t recognise any change in midi state. The main myBus object is recognised by printing in draw(). Looks like controllerChange() or notOn/Off() isn’t activating.

Is this a known bug? Any recommendations including alternative libs?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 17, 2019, 9:40am UTC](https://discourse.processing.org/t/themidibus-python/10382/2 "2019-04-17T09:40:23Z")

</div>

> [@Guido cannot work in python mode](https://discourse.processing.org/t/guido-cannot-work-in-python-mode/9501/5):
>
> For such libraries, see whether they offer an alternative way to pass a custom callback (generally an instance of some functional interface provided by the library) besides those callbacks directly defined in the PApplet sketch. smirk_cat

---

<div class="post-metadata">

**Author:** ![lnp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lnp/32/4911_2.png) [@lnp](https://discourse.processing.org/u/lnp)\
**Post date:** [April 17, 2019, 10:08am UTC](https://discourse.processing.org/t/themidibus-python/10382/3 "2019-04-17T10:08:46Z")

</div>

Feck. The above info sounds beyond my knowledge at present.

Odd thing is it sometimes (after relaunching processing) gets as far as returning a callback print but stops short of the actual data - stops here: print("--------"). Then it seems to basically crash without crashing as nothing is called back. Then I have to relaunch processing to get that far again.

Do you know of any midi library tried and trusted in py mode?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 17, 2019, 5:01pm UTC](https://discourse.processing.org/t/themidibus-python/10382/4 "2019-04-17T17:01:34Z")

</div>

[SmallButDigital.com/docs/themidibus/index.html?themidibus/package-summary.html](http://SmallButDigital.com/docs/themidibus/index.html?themidibus/package-summary.html)

> <https://github.com/jdf/processing.py/issues/206>

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 19, 2019, 11:24pm UTC](https://discourse.processing.org/t/themidibus-python/10382/5 "2019-04-19T23:24:22Z")

</div>

…so, according to that issue, jdf included MidiBus callback support in Processing.py in

> <https://github.com/jdf/processing.py/commit/e3ad947f0421bc72b3393d05a1d8a0fa80446fbc>

The specific methods for noteOn / noteOff / controllerChange are at the bottom of the commit.

---

<div class="post-metadata">

**Author:** ![pintor](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pintor/32/11554_2.png) [@pintor](https://discourse.processing.org/u/pintor)\
**Post date:** [December 24, 2020, 3:13pm UTC](https://discourse.processing.org/t/themidibus-python/10382/6 "2020-12-24T15:13:43Z")

</div>

Hey folks, I have the following code, but still can’t get the noteOn to be called (even though the note is played), did you manage to get it working?

```auto
add_library('themidibus')
    
def setup():
    global myBus
    size(400, 600)
    
    MidiBus.list()
    myBus = MidiBus(this, -1, "IAC_MIDI")

    
def draw():
    channel = 0
    pitch = 64
    velocity = 127

    myBus.sendNoteOn(channel, pitch, velocity)
    delay(2000)
    myBus.sendNoteOff(channel, pitch, velocity)
    
    
def noteOn(channel, pitch, velocity):
    print("here")
    print(channel)
    print(pitch)
    print(velocity)

```

EDIT: Just noticed that in order for the callbacks to work, we need to set an input on the MidiBus like `MidiBus(this,"IAC_MIDI", "IAC_MIDI")`. Now it’s working fine 😅

EDIT 2: For some reason it just stopped working, so I still need help 😕

EDIT 3: I noticed that it works when I first open processing, but if I stop my sketch and run again, it doesn’t work anymore.
