# Midi controller / USB / synth / speaker?

**URL:** <https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173>\
**Category:** GameShell\
**Tags:** tinkering, usb, midi, music\
**Created:** [August 2, 2018, 7:54pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173 "2018-08-02T19:54:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michel\_Jones](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/michel_jones/32/439_2.png) [@Michel\_Jones](https://forum.clockworkpi.com/u/Michel_Jones)\
**Post date:** [August 2, 2018, 7:54pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/1 "2018-08-02T19:54:23Z")

</div>

Any luck anyone?  
Tried installing  
[http://www.samplerbox.org/home](http://www.samplerbox.org/home)

Plugged the USB with a midi controller and scratching my head…

---

<div class="post-metadata">

**Author:** ![Godzil](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/godzil/32/60_2.png) [@Godzil](https://forum.clockworkpi.com/u/Godzil)\
**Post date:** [August 3, 2018, 10:33am UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/2 "2018-08-03T10:33:52Z")

</div>

That should work, or should I say, it should be super easy if there is no driver for it, tu support USB MIDI devices. Linux (the kernel) have that in its set of drivers, so you will jsut need some software to support it (like SunVox or any other trackers, but would need a tracker that can be used using a D pad and some other buttons :D)

---

<div class="post-metadata">

**Author:** ![Michel\_Jones](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/michel_jones/32/439_2.png) [@Michel\_Jones](https://forum.clockworkpi.com/u/Michel_Jones)\
**Post date:** [August 4, 2018, 2:48pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/3 "2018-08-04T14:48:26Z")

</div>

Sunvox layout is too big for 320x240, wouldn’t work, it was very messy, have you gotten yours yet? Hope we can figure something cool here 😉

---

<div class="post-metadata">

**Author:** ![ComeauHH](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@ComeauHH](https://forum.clockworkpi.com/u/ComeauHH)\
**Post date:** [February 14, 2019, 7:50pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/4 "2019-02-14T19:50:14Z")

</div>

Bumping this thread up and hope that there are some other new owners interested in making this work!

Also tried my luck and flashed the .img of samplerbox on an SD. The Clockwork runs, but no sound so far/no visuals. Been trying it with an OTG Cable connecting to an Akai MPK Mini 2.

Somebody got an idea what to do?

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 7, 2020, 9:39am UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/5 "2020-02-07T09:39:44Z")

</div>

I see that this is not really active topic, but it’s the only one on this forum that mentions SamplerBox, so I’ll bump it 🙂

It took me by surprise to find SamplerBox preinstalled in the OS and that it’s not mentioned anywhere in the UI. I was using SamplerBox on Raspberry Pi before, so I tried to test it on CPI and it _kind of_ works. After connecting midi controller, I ssh’d to the CPI and tried running `python /opt/SamplerBox/samplerbox.py` and at first it was working, but after trying it again there was no sound. Turns out that if you `cd` into the SamplerBox folder and run `sudo python setup.py build_ext --inplace` each time before running SB the sound will work. But after trying to switch the preset (I added some preset from SB website) the sound disappears again.

I also tried to add it to the menu with .sh file with `python /opt/SamplerBox/samplerbox.py` in it, but it didn’t really work as after running it I was stuck with “loading” image and no way to cancel it. Is there a way to run something like this from the menu in verbose mode?

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 7, 2020, 2:20pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/6 "2020-02-07T14:20:06Z")

</div>

It’s funny. I was just looking at this yesterday, cleaning up stray config files etc throughout the system.  
The only reference made official was here:_emphasized text_

> [@GameShell OS image files (v0.3-0.4)](https://forum.clockworkpi.com/t/gameshell-os-image-files-v0-3-0-4/355/1):
>
> 1. Activated midi device support in Kernel by default (Tested with AKAI MPK mini, using USB OTG cable), preinstalled samplerbox in /opt

What if you copy it to the /user/local/bin location, then running an .sh script referencing it from within a directory containing all your presets etc? That should change the effective running folder.

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 7, 2020, 2:47pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/7 "2020-02-07T14:47:22Z")

</div>

> [@GameShell OS image files (v0.3-0.4)](https://forum.clockworkpi.com/t/gameshell-os-image-files-v0-3-0-4/355/1):
>
> What if you copy it to the /user/local/bin location, then running an .sh script referencing it from within a directory containing all your presets etc? That should change the effective running folder.

What exactly do you suggest copying to bin? I assume you are not talking about python script?

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 7, 2020, 2:51pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/8 "2020-02-07T14:51:43Z")

</div>

Yeah, something along these lines:

> [@](#):
>
> Simply strip off the `.py` extension by renaming the file. Then, you have to put the following line at the top of your file:
> 
> ```auto
> #!/usr/bin/env python
> 
> ```
> 
> `env` is a little program that sets up the environment so that the right `python` interpreter is executed.
> 
> You also have to make your file executable, with the command
> 
> ```auto
> chmod a+x htswap
> 
> ```
> 
> And dump it into `/usr/local/bin` . This is cleaner than `/usr/bin` , because the contents of that directory are usually managed by the operating system.

[source](https://stackoverflow.com/questions/1168042/python-scripts-in-usr-bin)

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 7, 2020, 3:05pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/9 "2020-02-07T15:05:19Z")

</div>

I guess I’ll give it a try, but I’m a little concerned that samplerbox consists of [3 python files](https://github.com/josephernest/SamplerBox), wouldn’t it break it if I copy only samplerbox.py to bin?

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 7, 2020, 3:18pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/10 "2020-02-07T15:18:12Z")

</div>

Try this possibly.

> [@](#):
>
> 1. Put the python files in a folder and then put this folder into an installation directory (may be in **/usr/local/foldername** ).
> 2. Use `chdir` in script/s to change directory to the file containing folder (may be `os.path.dirname(os.path.realpath(sys.argv[0]))` ) to import dependencies from there, or use absolute path.
> 3. Now make a symbolic link of the executable file and put it in **/usr/local/bin**.

[source](https://stackoverflow.com/questions/30825162/how-can-i-put-a-python-program-with-multiple-files-in-usr-local-bin)

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 7, 2020, 3:25pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/11 "2020-02-07T15:25:13Z")

</div>

Thanks. I’ll give it a try this weekend

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 9, 2020, 7:30pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/12 "2020-02-09T19:30:08Z")

</div>

After some trial, error and putting files into `/usr/local/bin` I found quite simple solution. All you need to do is just add a line `os.chdir(os.path.dirname(sys.argv[0]))` after all the imports into samplerbox.py. This way you can leave the script in `opt` folder and run it from wherever you wish, and .sh file with `python /opt/SamplerBox/samplerbox.py` works fine from the menu.

The only thing is it stays on “loading” screen if ran from the menu, and you can’t close it by pushing menu button. I’ve tried adding some code to address the menu button, but it didn’t seem to help, so I’ll need to investigate some more, then I’ll probably will post the solution here. And any ideas on how to hide “loading” screen? It would be nice to see the command line feedback from the script while it’s running

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 10, 2020, 2:09am UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/13 "2020-02-10T02:09:25Z")

</div>

Fantastic! Yeah, that is definitely a much easier solution, and much more relevant given you’re working with python! Nice work finding that!

Ugh, the dreaded loading screen. I’ve got a similar problem using scummvm, requiring the use of the F5 key to exit/access the system menu. Not easy to do via the gameshell. One solution I’ve been looking at is [“xbindkeys”](https://wiki.archlinux.org/index.php/Xbindkeys) and making a “rage quit kill key combo”, pushing ABXY+SEL+START at the same time; kinda the same as what you could do to soft reset the original Game Boy, mapping it to the magic [alt+sysrq](https://www.howtogeek.com/119127/use-the-magic-sysrq-key-on-linux-to-fix-frozen-x-servers-cleanly-reboot-and-run-other-low-level-commands/) key.  
If you find a more eloquent solution however, I would love to hear it.

> **For reference, here are the outputs according to xbindkey**
>
> Key code. name. snes mapping
> 
> c:111 Up up  
> c:116 Down down  
> c:113 Left left  
> c:114 Right right
> 
> c:45 k a (east)  
> c:44 j b (south)  
> c:31 i x (north)  
> c:30 u y (west)
> 
> c:46 l shift+a (east) or R2 (outer LK5)  
> c:43 h shift+b (south) or L2 (outer LK1)  
> c:32 o shift+x (north) or R1 (inner LK4)  
> c:29 y shift+y (west) or L1 (inner LK2)
> 
> c:65 space select  
> c:36 Return start  
> c:9 Escape menu
> 
> c:82 KP\_Subtract shift+sel  
> c:86 KP\_Add shift+start  
> c:22 Backspace shift+menu
> 
> c:112 Prior shift+L1 (inner LK2)  
> c:117 Next shift+R1 (inner LK4)  
> c:110 Home shift+L2 (outer LK1)  
> c:115 End shift+R2 (outer LK5)
> 
> nul nul shift (centre LK3)

I also just found [this](https://forum.clockworkpi.com/t/solved-how-to-quit-launcher-and-launch-other-pygame/4187)

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 10, 2020, 2:31pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/14 "2020-02-10T14:31:42Z")

</div>

Found a way to get rid of loading screen in my case… It’s quite logical to run the script in the terminal, so I changed my .sh file to `xterm -e python /opt/SamplerBox/samplerbox.py`. Now I can see the output of the script. The only thing left is to find a way to close the xterm using menu button. This rage quit combo might work, but I still hope to find a way to use menu button

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 11, 2020, 1:31pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/15 "2020-02-11T13:31:24Z")

</div>

If you make a profile that loads up upon executing your script, you could probably have it bind the menu key to whatever key combo you use to exit. Or the magic key.  
(And of course kill the process upon execution)

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 11, 2020, 1:40pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/16 "2020-02-11T13:40:59Z")

</div>

I was trying to bind `Esc` to `exit` in .sh file, but it didn’t work for some reason. could you please tell what kind of profile are you talking about so I can investigate how it can be done?

I also was thinking about adding handling of `Esc` in python script, but I think it would be cool to not change the script that much

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 11, 2020, 2:12pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/17 "2020-02-11T14:12:08Z")

</div>

Not a strict profile per se, but rather just a .xbindkeysrc file mapping the command required. If it’s not something included in the .xinitrc startup, it shouldn’t load with startup, making the menu key still functional.  
Just to make things return to normal, include this at the end of the definition, killing xbindkeys:

```auto
1. use this command to reset the keyboard shortcuts to default 

xbindkeys --defaults > ~/.xbindkeysrc

2. Then kill the `xbindkeys` daemon process with the command:

killall xbindkeys

```

[source](https://askubuntu.com/questions/196685/how-to-remove-bound-keys-created-in-xbindkeys)

The question is, is there a keystroke to exit, if using a full sized QWERTY keyboard?

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 11, 2020, 2:18pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/18 "2020-02-11T14:18:48Z")

</div>

thanks! I’ll try this as soon as I have some time

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [February 15, 2020, 5:07pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/19 "2020-02-15T17:07:42Z")

</div>

and I finally got it to work 🙂  
my .sh file now looks like this:

```
#!/bin/bash

xbindkeys -f ~/.bindsamplerbox 
xterm -e python /opt/SamplerBox/samplerbox.py 

```

and this `.bindsamplerbox` is like this

```
"killall xterm"
Escape

```

I know it’s not the most elegant solution, but it works. I also didn’t bother resetting the binding yet, might just add `&& killall xbindkeys` to the binding itself if I’ll have any issues

---

<div class="post-metadata">

**Author:** ![javelinface](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/javelinface/32/3079_2.png) [@javelinface](https://forum.clockworkpi.com/u/javelinface)\
**Post date:** [February 15, 2020, 6:11pm UTC](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173/20 "2020-02-15T18:11:47Z")

</div>

Nice work! Seems elegant to me. 🙂 This should almost be considered the official way to get samplerbox running on 0.5.  
I guess it could be more problematic to kill all xbindkeys if say, you’re using it for anything else. Chances are, if you’re using xterm you run anything else, you’d want a kill switch too.

[Next page](https://forum.clockworkpi.com/t/midi-controller-usb-synth-speaker/1173.md?page=2)
