Raspberry Pi Setup and Install (old version) - Linwood-F/MusicalPi GitHub Wiki
These are the steps I used for my Pi setup. It contained a Dell Touchscreen hooked up via HDMI and USB, a USB Audio dongle (for better quality audio output), and a bluetooth pedal for page turns. No soldering iron required. The Piano I used has a midi player built in (it is a PianoDisc system), and the program can (optionally) support one via ALSA and a USB Midi port. I also used the media capabilities in the Pi for playing Pianodisc music (which is audio-encoded midi, for which they have a large collection).
I chose Ubuntu Mate as the distribution; I liked the clean interface. I believe that the standard Raspian distribution will work generally, but i had trouble getting a decent virtual on-screen keyboard to work. In Mate, Onboard is available and works quite nicely, so it was a deciding factor.
Configure microSD Card
-
Download Ubuntu Mate for Pi (as of this writing here), I used 16.04.02 (general download page
-
Export the download using 7Zip or other programs to the IMG file.
-
Copy the IMG file to the microSD; on Windows I used Win32 Disk Imager, this should produce a bootable disk on the Pi. There is lots of information on other alternatives on the Raspberry Pi site.
-
This is best done with a 32 Gig SD microSD card. It will fit on a 16GB if you take steps to minimize disk space. While close to hitting the 16GB size during that build, it did complete when I last ran it. A 32Gig gives you plenty of room.
-
You may want a keyboard and mouse plugged in to make the following faster (especially cut and paste stuff).
-
For a touchscreen, it probably will not align properly out of the box due to a setting in the Mate distribution. To correct this, before you move on to the Pi itself, re-mount (if needed) the microSD on Windows. Edit the config.text (in the root folder, or /boot if you already moved to the Pi and are trying to fix it later) and set disable_overscan=1 (probably just uncomment) to make the monitor fit properly (at least for mine), and also set hdmi_blanking=1 (it probably needs to be added) so it will support auto-powerdown mode on the monitor. Touch screen support on the pi's remains pretty screen specific, so you may need to experiment.
-
Put the card in the pi and boot.
Initial Pi Configuration
-
Go through the startup. To use the visual keyboard you need to choose that profile from the top right corner.
-
Set the computer name and ID, and set auto-login (so when the piano powers up it is available; if you prefer to have to log in that is fine also).
-
After it boots the first time, due to a bug in the distribution, if wifi is not available; try rebooting a second time, or initially use a physical connection. The .02 version seemed OK, but just in case.
-
If you may need the on-screen keyboard; run this by using the universal access option from the left pulldown (we will make it automatic later).
-
Run the Raspberry Pi information option from the Welcome screen, and look a page or so down and run the option to expand the disk space. It should already be done (a new feature on 16.04.02). If not run it.
-
Now you should be able to select the wifi from the pull down menu on the top right, and connect. If entering a long password, you may not have time to do so with the touch keyboard, but you can edit the connection manually and enter the password there. Or you can defer this (we'll fix it later) if using a physical cable.
-
Once you get connected it is likely easier to do the rest from a ssh terminal session. SSH is installed in 16.04.02 by default but disabled. Start a terminal session from the desktop and:
sudo systemctl enable ssh sudo systemctl start ssh # if you want to try before the reboot
-
Reboot so you get a clean boot with all the disk available, and ssh should now be available.
-
Once back up, connect via SSH from a real terminal so you can do cut and pastes; if the name does not work for DNS, start a terminal session from the connected screen and enter ifconfig and get the IP (or get it from your DHCP server).
Config Best Done from a Real Keyboard/Mouse (e.g. ssh session)
-
You can use the wifi connection manager and let it connect automatically, or it may be better to hardcode the wlan info at this point by editing the /etc/network/interfaces file:
auto wlan0 iface wlan0 inet dhcp wpa-ssid YOURSSID wpa-psk YOURPASSWORD
-
If necessary put in a reservation. You could also change the above to hard code the IP address in addition to the SSID/password.
-
Consider updating the Pi firmware, e.g. from here. Note: It is not at all clear this is appropriate. There are postings indicating that a dist-upgrade (as below) is all you want for Jessie, but I have not been able to confirm if they work for Mate, and have seen some indications of mis-matched kernels when using it, so do your own research or maybe safest skip this step.
-
Update the distribution:
sudo apt-get update # I found it necessary to reboot before this would unlock sudo apt-get dist-upgrade
-
If you are running on a 16G SD card, you may want to free up some space by (for example) getting rid of Libre Office, if you do not plan to use it. You can via the following, but it only gets you about 250MB, you get a lot more if you remove the QT5 source after compilation and installation, and/or by removing the swap file.
sudo apt-get remove --purge libreoffice* sudo apt-get clean sudo apt-get autoremove
-
The following commands generally update the onboard keyboard, lock screen, etc. I found that this required (at least most times -- it worked occasionally) being run from the actual touchscreen session, so put it in a file as follows:
nano dodbus # add the following lines gsettings set org.mate.screensaver lock-enabled false gsettings set org.onboard.auto-show enabled true gsettings set org.onboard.auto-show hide-on-key-press false gsettings set org.onboard.window docking-enabled false gsettings set org.onboard layout "/usr/share/onboard/Full Keyboard.onboard" dbus-launch gsettings set org.mate.interface accessibility true dbus-launch gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false chmod +x dodbus # from the touch screen (terminal or run from the file browser) ./dodbus
-
To run the keyboard in auto-show mode you need accessibility enabled. The above tries (and a few other things I attempted) would not work, so the very first time you activate Onboard (and you should now on the touchscreen), it will prompt to enable accessibility. Do so and log out/in.
-
As of this version I found a lot of spurious entries in syslog, and numerous postings on the Pi forums suggest this: change /etc/rsyslog.d/50-default.conf, and comment out this section:
#daemon.*;mail.*;\ # news.err;\ # *.=debug;*.=info;\ # *.=notice;*.=warn |/dev/xconsole
-
Let's start installing prerequisites.
sudo apt-get install git cifs-utils libasound2-dev libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev build-essential perl python git '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libatspi2.0-dev libdbus-1-dev libsqlite3-dev sqlite3 sqlite libsqlite0-dev cifs-utils libegl1-mesa-dev libfontconfig1-dev cmake libjpeg-turbo8-dev libtiff5-dev libopenjpeg-dev
Configure Calibre share
-
If you have Caibre on a windows system, set up a share for it. This example points to a drive, and then lets the path be defined in the program; you could put to the explicit folder with Calibre in this as well, just adjust the code as appropriate for the path name. This is not a terribly secure way to put in the password, but you can use other techniques if needed:
sudo mkdir -p /mnt/hostname/folder sudo nano /etc/fstab # and add the line: //hostname.domain/folder /mnt/hostname/folder cifs username=yourwindowsname,password=yourwindowspassword,iocharset=utf8,sec=ntlm,uid=linuxuser,gid=linuxuser,nobrl 0 0 sudo mount -a # check for errors
-
The "nobrl" (No Byte Range Locking) is required for write access to the database. It is worth noting that concurrent write access to a SQLite database on a share is not recommended, and using the write feature may introduce a corruption risk to the shared database, especially if you update Calibre at the same instant MusicalPi updates it. MusicalPi reduces that risk by holding the database open only for the instant it needs to write.
Pull down software and build
For this iteration I am building QT (but not QTCreator), Poppler, and obviously my software from sources. This gets us the latest QT version, though as far as I know the distro version will work (I did it this way to get another piece of software to work, then decided not to use it, but decided I liked running on later versions just in case and did not go back). It uses ALSA from the distro version (already installed above). If you are not working on a "real" system for development, you may want to build QTCreator (the steps in my Hyper-V version should work here, though I did not try).
Note that compiling QT especially is very intensive, and the Pi 3B cannot handle it due to memory out of the box. To correct that, below I install a swap area for portions of the build that needed more memory. This is temporary and goes away; the normal runtime does not need it.
-
Set up swap file for subsequent builds (be sure again, that you expanded the disk size as above). In the following be sure to adjust for differences in device name if they appear. Note this creates a permanent swap file, but it is not permanently in use, so if you reboot only the last item need be done again. I found the device name changed from the 16.04 to 16.04.02 version, so yours may be different also. This does 1GB which is a balance between room for the compile and room on the disk.
sudo fdisk -l # find device name, e.g. /dev/mmcblk0p2 sudo mkdir /mnt/mmcblk0p2 sudo mount /dev/mmcblk0p2 /mnt/mmcblk0p2 sudo dd if=/dev/zero of=/mnt/mmcblk0p2/swap.file bs=1M count=1024 sudo mkswap /mnt/mmcblk0p2/swap.file sudo chmod 600 /mnt/mmcblk0p2/swap.file sudo swapon /mnt/mmcblk0p2/swap.file
-
Now create a build directory for QTCreator and QT itself, and pull those down and build. They are built in "shadow" directories based on QT's recommendations. First qt itself:
mkdir ~/qt-build cd ~ git clone git://code.qt.io/qt/qt5.git cd qt5 git checkout 5.8 ## only if you wish a specific version ./init-repository --module-subset=default,-qtwebkit,-qtwebkit-examples cd ~/qt-build
-
Continue with the configure, but note the documentation recommends using -no-gtkstyle, but I could not get that to work (it says there is no such parameter). I tried a number of things for configure, some aimed at getting webkit to build (but not needed for this project). These should work, but by no means is it necessarily the best. Note this sets up for an install to the default (distro) location, NOT the usual /usr/local location for home-built code. Note also that the make will take many hours (about 8 when I last did it, but depends a lot on your setup). Also, my last build caused the Pi to thermal limit due to the "j4". If you have good heat sinks and some airflow the "j4" is good; with no heat sinks or running in a case, consider using a smaller number to compile more slowly (and at a lower temperature).
cd ~/qt-build ## be sure you are there not the qt5 folder ~/qt5/configure -confirm-license -opensource -reduce-exports -nomake examples -no-compile-examples -skip qtwayland -nomake tests -release -prefix /usr -qt-pcre -evdev make -j3 # number of cores after the j
-
If you are trying to build on a 16GB card, you may now be almost out of space. If so, you might want to delete the swap file used, as the rest should be OK with the memory present. On my last build (with Libre Office gone) I had about 900 MB left at this stage, and it went up to about 2.5G free with the swap file gone. This is not needed if you have a 32 GB card.
sudo swapoff /mnt/mmcblk0p2/swap.file sudo rm /mnt/mmcblk0p2/swap.file
-
All the rest assumes things go in the normal place; you could work from your shadow directory, but this installs:
sudo make install -j4
-
You will need MidiFile, which is a project at Github at craigsapp/midifile, but I made some slight changes, so unless it has been updated, use my fork and branch as follows. The change is addition of two more logical functions for determining midi item types:
cd ~ git clone https://github.com/Linwood-F/midifile.git cd midifile git checkout addKeyTimeSignatures make library -j4
-
One reason I built poppler from source was to avoid the dependencies where it will pull down QT software on install, but another was to get the latest version. Build it now:
cd ~ git clone https://anongit.freedesktop.org/git/poppler/poppler.git cd poppler cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX:path=/usr make -j4 sudo make install
-
Note that the above requests the path be the non-local default, but when I run it, poppler ignores the prefix and installs in /usr/local, so make sure there's not also a distro/ppa installed version in /usr.
-
If you are using a development system, you may want to copy software from there to this system. If not, you can just clone the git repository to this system and build directly. Or if you fork my release, you can clone that. The latter can be done like this:
cd ~ git clone https://github.com/Linwood-F/MusicalPi.git cd MusicalPi qmake make -j4
-
For reference, following the above, at this point I had 1.2G available on the 16GB card at this point, so close but still ample room.
In your Calibre library:
-
Put in PDF's that are music
-
When scanning PDF's, crop TIGHT around the music to provide the largest image on screen
-
Tag each PDF that is musing with the tag "Music" (you can change this if desired in the constants)
Try It
-
Now if you run the project you should see your library appear and be able to display music.
-
Note that most settings are not in piconstants.h but in the settings file, which has defaults contained in the oursettings.cpp file. However, rather than changing them there, just run the program (let it fail on the library -- hopefully it will at least run), and go into settings and correct paths, midi ports, etc. Midi port only matters if you have an external midi keyboard.
RhythmBox and Pianodisc music
Here begins a long story I will just skip, of trying to get the Pi to take the place of the Apple Airport Express that comes with every Pianodisc system. Instead just some solutions. I decided we wanted to move our Pianodisc music library (over 1000 songs of piano or piano + accompaniment) onto the new MusicalPi system, so one could play not only Midi from there, but also the purpose-arranged Pianodisc music. That music is audio, not midi, and no converter (other than their hardware) could be found for changing to Midi. Plus many tracks have accompaniment, e.g. orchestra, and that requires audio. The Pianodisc standard is iTunes, through Airplay.
I experimented with various iTunes look-alike, but Apples encryption made actually using the Airplay problematic, so I shifted to using the Pi's output itself, and playing directly there. Doing that offered several alternatives, like Rhythmbox (in the distro), Audacious, etc. I settled on the relatively straightforward path of Rhythmbox. Getting it to play the audio requires a few extra pieces:
sudo apt-get install ubuntu-restricted-extras
I'm not sure I fully understand this, but those are items they cannot put in the main distro for copyright/IP issues (but yet they can be in a distro and be installed?). Maybe it's that it prompts for a license acceptance. Anyway, install the above. Now, if you also want to be able to do airplay TO the Pi (i.e. play music from your iPhone, etc. to the Pi's audio output), install this:
sudo apt-get install shairport-sync
Edit the file /etc/shairport-sync.conf and adjust as follows:
In the general section, put a name for your system:
name = "MusicalPi Pianodisc";
output_backend = "alsa";
drift_tolerance_in_seconds=0.010;
If you are using the built-in audio, also add:
volume_range_db = 30;
I used a USB Audio converter to try to get better quality - it was somewhat improved, but not a huge difference. I may have been better off with one of the daughter cards with a more serious DAC. The only issue I am finding though is the pianodisc calibration for levels does not respond properly to the Pi's output (you can calibrate with a direct connection from an iPhone, etc., then just use that calibration).
I put the rhythmbox library and playlists on my share (the shortcut below demonstrates).
For use with a touchscreen, you may want to change the font size. You can do that from the System, Preferences, Look and Feel, Appearance, and go to the fonts, and change the Application Font to 16 or so. Adjust as you see fit. This changes all applications generally but not the Musical Pi program, which is already sized for touch screens.
If you used a different audio device, you need to use the menu for Sound to change it to be the default output.
Beware that Rhythmbox's volume beings at 100%. Also, you may want to go into the menu's Sound option and turn off keyboard and window sounds (otherwise you get clicks and pops through the speakers if you are connected to the Piano's sound system).
Right click doesn't work !! -- Fix it
As soon as you decide to add a song to a playlist in Rhythmbox, you will see it requires a right-click, and it will not work.
A Right-click should be able to be implemented with settings in Xorg.conf to enable a long press. Despite everything I never got it to work, and fell back to a two-finger gesture that was provided on github. It is quite old, but appears to work fine.
-
Install prerequisites:
sudo apt-get install libxrandr-dev evtest
-
Clone and compile to make sure you can. Adjust by pulling in other prerequisites if needed.
git clone https://github.com/Plippo/twofing.git cd twofing make
-
Now customize to your touchscreen. Mine is a Dell S2240T, which is a "CoolTouch System", but you can get the details on which kind by running evtest from a terminal window. Run it, then just hit control-C, and look for this line:
Input device ID: bus 0x3 vendor 0x2575 product 0x8753 version 0x110
-
Now we customize the make's install section to include this. Look in the folder and copy:
cp 70-touchscreen-egalax.rules 70-my-touchscreen.rules
-
Now edit 70-my-touchscreen.rules and adjust so it looks like this, where the vendor, product and name portions are customized for you. Take the name from the name portion of evtest, but it does not have to be the whole thing:
SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="2575",ATTRS{idProduct}=="8753",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch" KERNEL=="event*",ATTRS{name}=="CoolTouch System",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
-
Edit the Makefile and change "70-touchscreen-egalax.rules" to "70-my-touchscreen.rules" so your file gets installed, then:
sudo make install
-
This will create a /dev/twofingtouch on the next boot. We also need the daemon to auto-start, since we are doing other auto-starts, do it the same way. Create ~/.config/autostart/startTwoFing.desktop
#!/usr/bin/env xdg-open [Desktop Entry] Type=Application Exec=/usr/bin/twofing X-MATE-Autostart-enabled=true Name=twofing Comment=Daemon for right click
-
Reboot and test. You can touch something to select, very quickly touch a second finger (anywhere nearby), then release -- the context menu comes up on the release, not the touch.
Setup to start automatically
I find the simplest is to place an entry for auto-start, but since we want these in desktop put them there:
nano ~/Desktop/startMusicalPi.desktop # create file and add lines as follows
[Desktop Entry]
Type=Application
Path=/home/useraccount/MusicalPi
Exec=/home/useraccount/MusicalPi/MusicalPi
X-MATE-Autostart-enabled=true
Name=MusicalPi
Comment=Sheet Music Reader
Icon=/home/useraccount/MusicalPi/MusicalPi.gif
Categories=Utility
This should put the the program on the desktop (we'll autostart in a minute). Note it may be tempting while debugging to put a Terminal=true in the desktop entry, but that will prevent autostart.
If you are using a player system, like my pianodisc, you may find you want to run Rhythmbox (or some other music player) as well. I wanted the library off on the share, not on the Pi itself where it can be lost. I did that by:
nano ~/Desktop/startRhythmbox.desktop
[Desktop Entry]
Type=Application
Path=/mnt/hostname/folder/rhythmbox_library
Exec=/usr/bin/rhythmbox --rhythmdb-file /mnt/hostname/folder/rhythmbox_library/rhythmdb.xml --playlists-file /mnt/hostname/folder/rhythmbox_library/playlists.xml
Name=Rhythmbox
Comment=Pianodisk Player
Icon=/home/account/MusicalPi/MusicalPi.gif
Categories=Utility
I also found that despite having everything I could find set up, Onboard would not routinely start on startup, and needed to be manually invoked. This seemed to work around it:
nano ~/.config/autostart/startOnboard.desktop # create file and add lines as follows
[Desktop Entry]
Type=Application
Exec=onboard
Hidden=false
X-MATE-Autostart-enabled=true
Name=Virtual Keyboard
Comment=Virtual Keyboard
Finally it is handy to have the application listed in the menus and on the desktop, that can be done as follows. The same file can be used for all three purposes. This puts it into the Utilities (Accessories) menu, you can adjust as you prefer:
mkdir -p ~/.local/share/applications
ln ~/Desktop/startMusicalPi.desktop ~/.local/share/applications/MusicalPi.desktop
ln ~/Desktop/startMusicalPi.desktop ~/.config/autostart/MusicalPi.desktop
chmod +x ~/Desktop/startMusicalPi.desktop
chmod +x ~/Desktop/startRhythmbox.desktop
chmod +x ~/.config/autostart/startOnboard.desktop
Reboot and try it
Hopefully it will start and run, and see the library.
I had a lot of trouble with OnBoard. When I build a new copy of the OS, I seem to always have to go in by hand and enable the auto-show feature, then enable accessibility. The command lines above do not seem to work completely. Your mileage may vary.
Review this (https://www.leferguson.com/musicalpi-piano-sheet-music-display-qt-version-runs/) for some running tips.