Invisible Piano (Keyboard Anywhere, a Kinect Piano)

Introduction: Invisible Piano (Keyboard Anywhere, a Kinect Piano)

After writing my previous instructable, I was asked about installing some slightly different software to use with the Kinect. Since I'd already done it, I figured it wouldn't take to long to retrace my steps and write the instructable. After much frustration, I figured out a really easy process to get everything installed and talking.

This instructable with walk you though getting a virtual keyboard working with the current release (11.04) of Ubuntu.

There are other ways of doing this (which I've done in the past), but trying to reaccomplish the task, I found many shortcuts to what I did in the command line previously.

If you have any questions on the command line or getting around in Ubuntu, please see my previous instructable. In this instructable I will assume you have a basic knowledge of the system and how it works. Like my last instructable terminal commands will be given starting with $. Do not copy the $ when transposing.

Also, don't transpose anything to terminal between [ ], it's there for reference.

Step 1: Materials

Step 2: Install Ubuntu

I downloaded and installed the 32 bit version onto my laptop, then used Update Manager to update the system (there was a couple hundred megs worth of updates).

Bonus info:
For this release, Ubuntu decided to ditch Gnome and move to Unity, their out User Interface.

Like any new system, if you haven't used it before, it's going to take some getting used to. I can say after using it for a while, getting pissed and moving to Debian (and Gnome 3) for a while, then coming back and trying it again, it's not that bad. It's not my first choice in desktops, but that's because it's different that what I'm used to and is going to take me some time to come around. The important bit is that it works, it's useable, and the design is such as to try to make it as user friendly as possible.

Step 3: Open Kinect

After the system is installed and the updates are complete, The first program you're going to need is OpenKinect.

They have excellent instructions on their webpage to get this installed: click here, and follow the Ubuntu Manual Install instructions.

When you're finished with this step, your Kinect should be visible on your computer.

Step 4: Python

The Keyboard Anywhere script is written in Python, which OpenKinect can't deal with in its regular installed state. Happily, there is a Python Wrapper that allows the two to work together.

Thankfully, when you installed OpenKinect in your last step, it downloaded the python wrapper on your computer. The problem is that while it downloaded, it didn't install.

If you go to your home (where home is your username) directory: home/libfreenect/wrappers/python you'll see the information about the wrapper. You can open the README to see instructions on installing.

For ease of time and those who like to copy-paste
$ sudo apt-get install cython python-dev python-numpy [these need to be installed before we can install the python wrapper]

Navigate your way, in terminal, to the python folder. If you close and open terminal:
$ cd libfreenect/wrappers/python

and then install:
$ sudo python setup.py install

** Instruction addition as per tdinsmoor in the comments below **
If you are having dependency issues with libexpat1-dev (on Ubuntu 12.04), you'll need to download and install a separate .deb package to fix it.
For AMD64 systems:
http://launchpadlibrarian.net/118383909/libexpat1-dev_2.1.0-1ubuntu1_amd64.deb
For i386 systems:
http://launchpadlibrarian.net/118383396/libexpat1-dev_2.1.0-1ubuntu1_i386.deb

Ubuntu software center may give you an error at first, but ignore this and proceed to install python2.7-dev and python-dev with:
$ sudo apt-get install python-dev python2.7-dev

The packages should now install correctly, and you may proceed to install the wrapper.************

Step 5: Keyboard-Anywhere - Dependencies and Downloads

All the information below can be found by reading the README provided in the package you can download at the previously mentioned link. There are some discrepancies in the instructions provided which I have fixed for this instructable. (i.e. pyqt4-devtools should read pyqt4-dev-tools and fluid-soundfont-gm doesn't require install because it's part of the fluidsynth package) I've also left out dependencies that have been installed in previous steps.

Finally, if you haven't yet, click downloads at the top and click tar.gz
-unpack it onto your computer where ever it downloaded (I will assume it's the Downloads folder)

If you scroll to the bottom you'll see links to download both QGLViewer and PyQGLViewer
-We're going to skip this for now.

Step 6: QGLViewer and PyQGLViewer

The instructions given in the Keyboard-Anywhere README for installing these files, is difficult at best, nightmarish at worst. Instead of following those directions, I've opted to install it a completely different way. You can find my instructions at this link.

--------------------------
If you want to downloaded and install QGLViewer and PyQGLViewer manually, after downloaded and unpacking the files, ensure you complete the following steps to correct errors that will come up.

Navigate to /home/Downloads/libQGLViewer-2.3.9-py/QGLViewer/

Open QGLViewer.pro in gedit (or whatever default application may open in)

One of the only forums I could find that was helpful was this one. If you try to progress in these steps, you'll get that error.

I will not be providing any more directions on manually installing QGLViewer and PyQGLViewer. If you'd like to manually install them, follow the directions in their README/INSTALL files.
--------------------------

Step 7: PyFluidSynth

FluidSynth, for some reason, doesn't play nice with the python scripts that are trying to use it. To fix this, I installed pyFluidSynth. It seems to work nicely.

Step 8: Enjoy!

Everything is now installed, all you have to do is run Keyboard Anywhere.

Navigate to the appropriate directory, and run using the python command.

You need to use sudo, or you don't have enough permissions to do everything.
Unfortunately I've found that sudo, and su both have a timer on them. So after 30-45 minutes, you'll need to close the program and start it up again. I haven't found a way around this yet.

The README that is associated with the downloaded Keyboard-Anywhere file has detailed instructions on what to do once running.
If you're comfortable editing python script (it's not too difficult after it's already been written...you're just changing things), you can open the keyboard_anywhere.py file in gedit and change the size of the keys and link to different sound files.

If you have any questions or comments, feel free to leave them below.

Comments

Thanks for the writeup. What is the difference between libfreenect, openkinect and the software you used in your other tutorial? I have a Kinect, want to hook it up in Linux and interact with it using Python. I thought libfreenect is the best way to do this?

Hi, im not sure if someone can help me with a problem... at the moment when i try to use "sudo apt-get install pyqglviewer" i can't download the packages so i try to install it manual but have problems too. I appreciate if someone can help me with that

I've very sorry. All the software in this instructable is a year and a half old, and most of it has been updated since I posted this. Since I haven't kept up on new Kinect software since I wrote this up, I'm not sure how everything interacts with all of the new software.

Please ensure you're following the OpenKinect's read me/install files and that you're installing all of the dependencies. Other then that advice, I'm not going to be any help.

I have used Instructable website to get an idea to my project which was very useful to us. My project is Invisible Piano Keyboard anywhere I downloaded all the software needed as well as the hardware, but I have the following error whenever I tried to run it:

I'm sorry, I haven't used the application in long enough that I couldn't say what might be wrong. It kind of sounds like you're missing a dependency though. Make sure you install all of the required items first.

I really appreciate you posting this here, it's quite an amazing feat. Just wanted to let you know, the install for python-dev did not work for me. This was on a brand-new install, so it might be broken for everybody. It gave me the following error message on 12.04 Precise:

The following packages have unmet dependencies: python-dev : Depends: python2.7-dev (>= 2.7.3) but it is not going to be installed E: Unable to correct problems, you have held broken packages.

Now, I've tried to get the packages they depend on, (python-dev -> python2.7-dev -> libexpat1-dev [ Depends: libexpat1 (= 2.0.1-7.2ubuntu1.1) but 2.1.0-1ubuntu1 is to be installed {I have no idea why this is happening}] -> libexpat1 [which I have already]) and looked all around to try to fix this (especially the "broken packages" part, and tried a reinstall of all my packages after purging), maybe python 2.7.3 is no longer supported on 12.04 (as newest python is 3), but I have little idea. The strange thing is, I got it working before, but I ignored all the warnings and proceeded with the next step anyway. After trying to install GTK3+ (I wanted to try compiling some source code for a 3d-modeling program), my Ubuntu install broke for whatever reason (wouldn't even get to login screen), and I don't want to go through that again.

I'm an Ubuntu noob (trying, though). Could ya help a brother out? Please email me at tdinsmoor13@gmail.com if you or anybody is having the same problem and found a solution, or the possibility of a solution.

If you open Terminal, and type "python" into the prompt, you'll see which version of python you have installed on your system. You can use Ctrl-D after you figure out to backtrack out of the python interface back to the Terminal prompt. I'm running an updated (as of today) Ubuntu 12.04 system. My system has Python 2.7.3 installed on it. While Python 3 is out, it doesn't always work with everything, so it's not being rolled out in mass just yet. If you've upgraded to Python 3, you should try reverting, that could be the cause of your problem.

You should also check out the Ubuntu Install over at OpenKinect, it looks like libfreenect causes some issues with 12.04. I think you just need to follow the Official Packages install instructions for that portion.

Once you get that installed, make sure you follow the directions on the Python Wrappers Read Me. The directions there are going to be far more current then the code in my instructable. It looks like the only super requirements right now are getting cython, python-dev, and python-numpy. So install those before you try to compile.

If it doesn't work with following their instructions, then something in 12.04 may have mucked things up. You could try installing everything on an older build of Ubuntu as that might fix it. I know it worked on 11.04, but if it's not Ubuntu's fault, and something was changed in the OpenKinect code with dependancies, then I'm not sure what the problem might be.

I'm not sure if this helped at all, but best of luck. Is your only goal to get the Kinect display working, or do you need this specific app to run?

I've got it to work, just long story short, it was giving me trouble with python-dev, saying that I needed dependencies that I already had installed (on the manual install that you instructed)

The only reason why I posted here is that I was worried that this led up to my Ubuntu install breaking, because I used manual install then, but ignored the error (being the super-noob I was at the time). After I got it workIng (the keyboard-anywhere) I tried installing GTK3+ so I could try to compile the source code for a 3D model capturing program that needed it. I was just worried that the error I ignored before led up to my system failure, but that seems unlikely.

Just trying to rule out possibilities, because I don't know what exactly caused it, so that I don't do it again when I try again. (I don't expect help from here, seeing as how this isn't the place. Thank you for your quick response, and the instructabke!

====So, I make sure I have all my python packages... ====Now, this is when python-dev refuses to install:

dinsmoor@Dinsmoor-MU:~/libfreenect/wrappers/python$ sudo apt-get install python-dev Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

The following packages have unmet dependencies: python-dev : Depends: python2.7-dev (>= 2.7.3) but it is not going to be installed E: Unable to correct problems, you have held broken packages.

===And then I try to get python2.7-dev (but python reports that i's already 2.7.3):

dinsmoor@Dinsmoor-MU:~/libfreenect/wrappers/python$ sudo apt-get install python2.7-dev [sudo] password for dinsmoor: Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

The following packages have unmet dependencies: python2.7-dev : Depends: libexpat1-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages.

Then I try to get libexpat1-dev...

dinsmoor@Dinsmoor-MU:~/libfreenect/wrappers/python$ sudo apt-get install libexpat1-dev Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

The following packages have unmet dependencies: libexpat1-dev : Depends: libexpat1 (= 2.0.1-7.2ubuntu1.1) but 2.1.0-1ubuntu1 is to be installed E: Unable to correct problems, you have held broken packages.

====This one says it needs libexpat1, but it gives me a funky thing about it not ====being the right Ubuntu? I'm not sure how to interpret this. Anyway, I try for ====libexpat1..

====So, it's something to do with my system? If you could help me out man, I'd be so grateful. I'll post anything you need me to have it spit out. I'm just at a loss, since I got it working once, doing the exact same thing. (minus the system failure)

No, Sir... Giving me same result. I scoured Google for hours looking for a solution, and I've found and tried that solution (and again now, just to double-check for you) I've tried everything that comes to mind. Everything on others' minds. Doesn't make sense to me.

Got any more magic up your sleeve? Or should I ask the Ubuntu community?

Just had to know what to look for. Hey, thanks for trying to help me, but here's a solution for some people. You may need to modify your instructions for python wrapper, some of my students were having the same problem, even with a fresh Ubuntu 12.04 install.

Instruction addition: ** If you are having dependency issues with libexpat1-dev (on Ubuntu 12.04), you'll need to download and install a separate .deb package to fix it. For AMD64 systems: http://launchpadlibrarian.net/118383909/libexpat1-dev_2.1.0-1ubuntu1_amd64.deb For i386 systems: http://launchpadlibrarian.net/118383396/libexpat1-dev_2.1.0-1ubuntu1_i386.deb

Ubuntu software center may give you an error at first, but ignore this and proceed to install python2.7-dev and python-dev with: $ sudo apt-get install python-dev python2.7-dev

The packages should now install correctly, and you may proceed to install the wrapper. **

Also, if you have student just trying to learn about the Kinect, how it works and getting into the mechanics of it, I found Processing and this library incredibly useful. They're easy to install, and worked straight away for me.

Thank you for the links and also the recognition!I'll look at the links, and see how they like it.This exercise was more of a "figure it out, fool" type of experiment, a chance for them to do it themselves.You're welcome and thank you!

That's awesome! Thanks so much for letting me know what the fix was! I've edited this step to reflect your suggestion. Please let me know if you find anything else. It's really hard to keep software instructions up to date when you no longer work with the software, so I really appreciate the update!

That would be possible, but difficult. When people were between the camera and the note, it would block the note. It'd be better to use pressure sensors for that, and you can make those for pretty cheap depending on what you need.

Thank you!!! It's good to see someone finally sorted through all the problems with dependencies and such. I would hate to see such an amazing think like a kinect piano go to waste because the open source community can't get their tools to work together, and you've made sure that won't happen. Awesome.