Moode Audio Player for Raspberry Pi

Wow! Thank you very much for this great piece of software.
I am really amazed how good a raspberry pi together with a hifiberry dac+ running moOde can sound.
I love the way i am rediscovering my music collection and the world of internet radio stations.

It even inspired me to start my first raspberry project.
I bought a cheap little touchscreen (waveshare spotpear 3.2, 320x240)
to fit on top of a raspberry pi 2B.
The goal is to make a little radio running moOdeaudio, but also can be controlled on the touchscreen so my kids can use it without the need to get a phone or tablet.
Ofcourse the webinterface of moOde audio is not suitable for such a small screen so i am making a pygame program to run as a local small screen MPD client on top of a moOde audio system.
I started with the beautifull program RPi-Tron-Radio (https://github.com/5Volt-Junkie/RPi-Tron-Radio)
and changed the script to my needs.
This is how it looks:
attachment.php


I changed the volume control so it uses knob.sh instead of calls directly to MPC so it stayes in sync with the moOdeaudio webclient.

Now i would like to also include a cover art image on the little screen. But i don't know how to do that.
Would it be possible to create a script like knob.sh to get the url of the cover art picture displayed in the moOde web client?
I think the information i need is located in the file /var/www/js/player_lib.js in the var MPDCS.coverurl. But i have no clue on how to read that information and get it into my python script.
I am new to raspberry's and python scripting (this is my very first attempt at it) so maybe i am missing something obvious. But any help would be much appreciated :D

Hi,

This is really nice :)

When u finish the project, please email me the complete bill of materials and software config - tim at moodeaudio dot org.

I'm starting to work with some diy guys on displays and configs that could be integrated into Moode. I'd like to see if its possible to have several display options that could be fully automated. Just pick from a dropdown and reboot :)

(1) I'm glad to see that knob.sh is performing well. It has been greatly improved in Moode 2.4.

(2) Use this url for getting song file cover art
"http://moode/coverart.php/PATH-TO-SONGFILE.EXT"

Ex: "http://moode/coverart.php/USB/Music/Azymuth/Tightrope Walker/Brazil.m4a"

(3) There is no external method at this time for getting radio station covers, or for accessing the logic that handles the oddities in certain radio stations and audio file formats. I'll see if I can make something to get the radio station covers :)

Regards,
Tim Curtis
 
Thanks for the kind reply's!

The bill of materials is a short one:
1) one working moOdeaudio system running 2.4 with your favorite audio output
2) waveshare spotpear 3.2 v3 (320x240 3.2 inch cheap chinese touchscreen. Available on aliexpres and ebay)

I am shure it is also possible to make it work with other small touchscreens, like de adafruits which seem quite popular.

On the software:
1) start with a working moOdeAudio 2.4 setup.
2) expand the sdcard using the moOdeAudio config menu
3) install the touchscreen drivers. I used information on this website: https://github.com/swkim01/waveshare-dtoverlays
4) install the XSERVER package and calibrate the touchscreen. I used information on this website: Moode Audio on Raspberry Pi with SainSmart 7inch Touch-Screen LCD
5) install pygame (sudo apt-get install python.pygame)
6) Get the RPi-Tron-Radio python script from https://github.com/5Volt-Junkie/RPi-Tron-Radio.

If it's helpfull for anyone, i can provide a full list of all the SSH commands and file listings in order to execute that list on your system.

I am still working on adapting that script to my taste, but it is running on moOde out of the box playing internet radio. I have already changed the volume control so it uses knob.sh instead of calls to MPC. That way the volume stays in sync with the volume knob on the webclient. Also i changed the way track information is displayed on the screen because the tron radio script only expects internet radio information.
On the to-do list i have the mute buttton (should be easy also using knob.sh) and some way of selecting different playlists using MDC commands.
And ofcourse trying to get the coverart picture to the small screen.

Ofcourse i am willing to give the final result of that python/pygame script to anyone who's interested. But bare with me, it's my very first attempt at python scripting, and progress is very slow ;-). But you can also start with the RPi-Tron-Radio script and adapt it yourself. It is already running on top of moOde right out of the box.

A few questions/reactions for mr. Tim Curtis:

1) I have changed knob.sh in order to make my python script simple. Maybe you can consider to include that in a new distribution. The change i did is when knob.sh is called with argument ?, it echo's with the current knob volume setting and exit's with 0. Maybe it would also be usefull to add argument + and - to knob.sh for use by diy guys for easy volume ajustment.

2) That is a dangerous link you gave me. I used it wrong, and it killed moOde. It went offline and i had to start with a new image again. (No problem ofcourse, that's the risc of toying around with unknown software ;-)

3) i think the best way would be to write the tag that fills the coverart picture on the moOde webclient also to a .conf file, just like the knob_volume_setting is written to tcmods.conf. Than we can make a simple script, similar to knob.sh, to read that file and get the info into the python/pygame script
 
It went offline and i had to start with a new image again
That's one thing with the raspberry pi in general (not moode itself) is that it can "eat" or mess with the sd cards if not being careful. There is for example a button on my DAC that switches between spdif/analogue/line input, and if I click on it it messes up the image and kills moode.
Once rebooting, moode becomes very unstable - starts off OK, but after a while user www-data/process php5-fpm and mpd spikes the CPU usage leading to the pi eventually freezes up. The cpu spikes only happens when clicking on play and pause.

What does the php5-fpm do? Is this the webinterface scripts?
 
Last edited:
Thanks for the kind reply's!

The bill of materials is a short one:
1) one working moOdeaudio system running 2.4 with your favorite audio output
2) waveshare spotpear 3.2 v3 (320x240 3.2 inch cheap chinese touchscreen. Available on aliexpres and ebay)

I am shure it is also possible to make it work with other small touchscreens, like de adafruits which seem quite popular.

On the software:
1) start with a working moOdeAudio 2.4 setup.
2) expand the sdcard using the moOdeAudio config menu
3) install the touchscreen drivers. I used information on this website: https://github.com/swkim01/waveshare-dtoverlays
4) install the XSERVER package and calibrate the touchscreen. I used information on this website: Moode Audio on Raspberry Pi with SainSmart 7inch Touch-Screen LCD
5) install pygame (sudo apt-get install python.pygame)
6) Get the RPi-Tron-Radio python script from https://github.com/5Volt-Junkie/RPi-Tron-Radio.

If it's helpfull for anyone, i can provide a full list of all the SSH commands and file listings in order to execute that list on your system.

I am still working on adapting that script to my taste, but it is running on moOde out of the box playing internet radio. I have already changed the volume control so it uses knob.sh instead of calls to MPC. That way the volume stays in sync with the volume knob on the webclient. Also i changed the way track information is displayed on the screen because the tron radio script only expects internet radio information.
On the to-do list i have the mute buttton (should be easy also using knob.sh) and some way of selecting different playlists using MDC commands.
And ofcourse trying to get the coverart picture to the small screen.

Ofcourse i am willing to give the final result of that python/pygame script to anyone who's interested. But bare with me, it's my very first attempt at python scripting, and progress is very slow ;-). But you can also start with the RPi-Tron-Radio script and adapt it yourself. It is already running on top of moOde right out of the box.

A few questions/reactions for mr. Tim Curtis:

1) I have changed knob.sh in order to make my python script simple. Maybe you can consider to include that in a new distribution. The change i did is when knob.sh is called with argument ?, it echo's with the current knob volume setting and exit's with 0. Maybe it would also be usefull to add argument + and - to knob.sh for use by diy guys for easy volume ajustment.

2) That is a dangerous link you gave me. I used it wrong, and it killed moOde. It went offline and i had to start with a new image again. (No problem ofcourse, that's the risc of toying around with unknown software ;-)

3) i think the best way would be to write the tag that fills the coverart picture on the moOde webclient also to a .conf file, just like the knob_volume_setting is written to tcmods.conf. Than we can make a simple script, similar to knob.sh, to read that file and get the info into the python/pygame script

Hi,

How about knob.sh with no args prints the current volume setting?

Knob.sh in Moode 2.4 takes args "up <step>" and "down <step>" for example knob.sh up 3, knob.sh down 3. Similar to +/-.

Moode uses /coverart.php/PATH-TO-SONGFILE.EXT" internally so should be ok for script to call providing it can get the song file path. Radio station logos not externally accessible yet.

How does python script get the song info?

Regards,
Tim
 
That's one thing with the raspberry pi in general (not moode itself) is that it can "eat" or mess with the sd cards if not being careful. There is for example a button on my DAC that switches between spdif/analogue/line input, and if I click on it it messes up the image that kills moode.
Once rebooting, moode becomes very unstable - starts off OK, but after a while user www-data/process php5-fpm and mpd spikes the CPU usage leading to the pi eventually freezes up. The cpu spikes only happens when clicking on play and pause.

What does the php5-fpm do? Is this the webinterface scripts?

Hi,

Very odd ("messes up the image"). What DAC are u using?

If u are curious :) Moode 2.x has many component parts. It consists of PHP, JQuery/Javascript, HTML, CSS and BASH source code, a set of configuration files and a SQL database that contains player settings and configuration.

There are 71 source code files, 7 SQL database tables and 10 configuration files. Source code includes 19 PHP, 29 Javascript, 4 BASH, 14 HTML, and 5 CSS. Many other support files exist but are not generally involved in feature coding or bug fixes.

Main Infrastructure Components
- Raspbian based OS
- MPD music server
- PHP5 scripting server
- NGINX Web server
- SQLite database engine
- Zend Media PHP-Reader
- Libav-tools audio codecs
- libSoX resampler
- USBmount storage auto-mounter
- Shairport-sync Airplay receiver
- DJmount miniDLNA server
- upmpdcli UPnP renderer for MPD
- upexplorer UPnP metadata provider
- Samba CIFS/SMB file sharing
- JQuery Javascript
- JQuery Knob
- JQuery Countdown
- JQuery Scroll
- Twitter Bootstrap
- Designmodo Flat UI
- Font Awesome
- WiringPi GPIO interface
- IQ_rot rotary encoder driver
- Knob.sh volume knob cli

The architecture is client/server. Diagram attached.

Regards,
TC
 

Attachments

  • moode-arch.png
    moode-arch.png
    30.9 KB · Views: 364
Hi Tim,

Knob.sh with no arguments returning the current value would be fine.
up and down arguments is great. This will be in the final 2.4?

I use mpc -f [%title%] to get the track title information in python script
the code is lines = subprocess.check_output('mpc -f [%title%]', shell=True).split("\n")
The first line of the responds contains the track title. The second line gives the player status and time information.
Then i cal mpc -f [%artist%] and mpc -f [%album%] to get this information.
If mpc -f [%artist%] come up empty, moOde is playing a radio station and i use mpc current to get the station info
 
Hi Tim,

Knob.sh with no arguments returning the current value would be fine.
up and down arguments is great. This will be in the final 2.4?

I use mpc -f [%title%] to get the track title information in python script
the code is lines = subprocess.check_output('mpc -f [%title%]', shell=True).split("\n")
The first line of the responds contains the track title. The second line gives the player status and time information.
Then i cal mpc -f [%artist%] and mpc -f [%album%] to get this information.
If mpc -f [%artist%] come up empty, moOde is playing a radio station and i use mpc current to get the station info

Hi,

Yes updated knob.sh will be in final 2.4 (end of Oct).

I see that's a bit of work just to get the metadata. I'll just write a file with the metadata and coverurl that can be easily parsed. It will contain the cover url for radio station and song file. This will be in 2.4 final :)

The file would only contain four lines representing the metadata for the current song. It will probably be named /var/www/currentsong.txt.

Here are some examples:

(1) Radio Station, local cover, title tag not present in stream

artist: Radio Station
album: Radio Monte Carlo FM - RMC 1
title: http://shoutcast.unitedradio.it:1103
coverurl: images/webradio-logos/Radio Monte Carlo FM - RMC 1.png

(2) Radio Statio, remote cover, title tag present in stream

artist: Radio Station
album: Groove Salad [SomaFM]
title: Luke Vibert - Space Race
coverurl: http://somafm.com/img3/groovesalad-400.jpg

(3) Song File, all tags present

artist: Adele
album: iTunes Live From SoHo
title: Crazy for You (Live)
coverurl: /coverart.php/NAS%2FMusic%2FAdele%2FiTunes%20Live%20From%20SoHo%2F01.%20Crazy%20for%20You%20(Live).m4a

Regards,
Tim
 
Thanks for the kind reply's!

The bill of materials is a short one:
1) one working moOdeaudio system running 2.4 with your favorite audio output
2) waveshare spotpear 3.2 v3 (320x240 3.2 inch cheap chinese touchscreen. Available on aliexpres and ebay)

I am shure it is also possible to make it work with other small touchscreens, like de adafruits which seem quite popular.

On the software:
1) start with a working moOdeAudio 2.4 setup.
2) expand the sdcard using the moOdeAudio config menu
3) install the touchscreen drivers. I used information on this website: https://github.com/swkim01/waveshare-dtoverlays
4) install the XSERVER package and calibrate the touchscreen. I used information on this website: Moode Audio on Raspberry Pi with SainSmart 7inch Touch-Screen LCD
5) install pygame (sudo apt-get install python.pygame)
6) Get the RPi-Tron-Radio python script from https://github.com/5Volt-Junkie/RPi-Tron-Radio.

If it's helpfull for anyone, i can provide a full list of all the SSH commands and file listings in order to execute that list on your system.

I am still working on adapting that script to my taste, but it is running on moOde out of the box playing internet radio. I have already changed the volume control so it uses knob.sh instead of calls to MPC. That way the volume stays in sync with the volume knob on the webclient. Also i changed the way track information is displayed on the screen because the tron radio script only expects internet radio information.
On the to-do list i have the mute buttton (should be easy also using knob.sh) and some way of selecting different playlists using MDC commands.
And ofcourse trying to get the coverart picture to the small screen.

Ofcourse i am willing to give the final result of that python/pygame script to anyone who's interested. But bare with me, it's my very first attempt at python scripting, and progress is very slow ;-). But you can also start with the RPi-Tron-Radio script and adapt it yourself. It is already running on top of moOde right out of the box.

A few questions/reactions for mr. Tim Curtis:

1) I have changed knob.sh in order to make my python script simple. Maybe you can consider to include that in a new distribution. The change i did is when knob.sh is called with argument ?, it echo's with the current knob volume setting and exit's with 0. Maybe it would also be usefull to add argument + and - to knob.sh for use by diy guys for easy volume ajustment.

2) That is a dangerous link you gave me. I used it wrong, and it killed moOde. It went offline and i had to start with a new image again. (No problem ofcourse, that's the risc of toying around with unknown software ;-)

3) i think the best way would be to write the tag that fills the coverart picture on the moOde webclient also to a .conf file, just like the knob_volume_setting is written to tcmods.conf. Than we can make a simple script, similar to knob.sh, to read that file and get the info into the python/pygame script

I'm interesting this touchable. Can you describe full list of SSH command should do? Sorry, I'm newbie for raspberry and linux.

Thank you
 
Here's my "recepy"

write the last available moOde image to sd card.
Connect the display to the raspberry, insert the sd-card and connect the power. Make sure the raspberry is connected to internet.
Setup the system to play (selecting the audio output ect.). Basically set up a working moOde audio system.
Then, use moOde setup menu to expand the sd card. The system will reboot now.

Now for installing de display and touch drivers using SSH (i use the program putty for this. Login with user root and password moode):

sudo mkdir -p /etc/X11/xorg.conf.d/

sudo wget https://gist.github.com/notro/63fc8f563b5f85010d30/raw/5e68d6c6df9471f973b3da5305e73a5017590a69/fbtft.conf -O /etc/X11/xorg.conf.d/fbtft.conf

git clone https://github.com/swkim01/waveshare-dtoverlays.git

sudo cp waveshare-dtoverlays/waveshare32b-overlay.dtb /boot/overlays/

sudo nano /boot/config.txt


This will open a text editor
Add the following to the bottom of this file:

dtparam=spi=on
dtoverlay=waveshare32b:rotate=270


Press ctrl-x to save the file and close the editor
Then the next config file:

sudo nano /boot/cmdline.txt

Add the following to this file, all text in this file must be one single line!
fbtft_device.custom fbtft_device.name=fb_wave32b fbtft_device.gpios=dc:22,reset:27 fbtft_device.bgr=1 fbtft_device.speed=48000000 fbcon=map:11 fbcon=font:VGA8x8 dma.dmachans=0x7f35 console=tty1 consoleblank=0 fbtft_device.fps=50

reboot, now we have an image on the waveshare! You 'll see the console messages on the display.
Now install xserver

sudo mkdir -p /home/pi
sudo touch /home/pi/.Xauthority
sudo chmod -R 775 /home/pi
sudo passwd pi


And set the desired password.
Now the actual install of xserver. This is needed for the raspberry to output a graphical mode to the display

sudo apt-get install xorg xserver-xorg xserver-xorg-core xinit libx11-dev libxext-dev libxi-dev x11proto-input-dev xinput evtest autoconf -y

This will take some minutes

sudo dpkg-reconfigure x11-common

(select anybody)

calibrate touch if needed. You only need to do this once to get the right calibration data for your touchpanel

sudo apt-get install xinput-calibrator -y
sudo apt-get install g++ -y
sudo apt-get install wget -y
wget http://github.com/downloads/tias/xinput_calibrator/xinput_calibrator-0.7.5.tar.gz
sudo tar xvf xinput_calibrator-0.7.5.tar.gz
cd xinput_calibrator-0.7.5/
sudo ./configure
sudo make
sudo make install
su pi
startx


start a new SSH connection

su pi
DISPLAY=:0.0 xinput_calibrator


Touch the crosshairs on the screen and use the output to make a permanent calibration
The output looks like this, only with different numbers ofcourse:

Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "134 3771 3809 293"
Option "SwapAxes" "1"
EndSection


Making the calibration permanent, therefor you need to write 2 config files
I don't know why it needs 2 files, but hey....it works!

sudo mkdir -p /etc/X11/xorg.conf.d/
sudo chmod -R 775 /etc/X11/xorg.conf.d/
sudo nano /etc/X11/xorg.conf.d/99-calibration.conf


Write the calibration config to this file:
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "134 3771 3809 293"
Option "SwapAxes" "1"
EndSection


sudo nano /usr/share/X11/xorg.conf.d/01-input.conf

And again, write the calibration config to this file:

Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "134 3771 3809 293"
Option "SwapAxes" "1"
EndSection


To run a pygame program like RPi-Tron-Radio you need to install pygame:

sudo apt-get install python-pygame

Don't be sorry. I am also a newby at raspberry and Linux and i have tried a lot of similar SSH listings found on the web to get my touchpanel alive. It was a lot of trial and error to get to this listing.
And i am sure it is not the most efficient or best solution. But it works for me.

Most information i have found on
https://github.com/swkim01/waveshare-dtoverlays
and
Moode Audio on Raspberry Pi with SainSmart 7inch Touch-Screen LCD
 
Thanks for the kind reply's!

The bill of materials is a short one:
1) one working moOdeaudio system running 2.4 with your favorite audio output
2) waveshare spotpear 3.2 v3 (320x240 3.2 inch cheap chinese touchscreen. Available on aliexpres and ebay)

Does the touch screen sit on top of the a HifiBerry or IQAudio Dac or does it require the use of a USB Dac? If so, do you need extra pins to connect it?
 
Benkit:
Thanks for that question. I consider it a compliment :)
But the touchscreen script is still in it's early stages and i have to wait for the 2.4 version myself for some new features i am gonna use in the script. Besides that, the script will only be usefull for systems with little touchscreens with a 340x240 resolution. I think that makes the userbase too narrow to let this be included in a full release. But maybe it can be somekind of optional extra on top of a standard moOde release.
I will make the final result available for Tim, and anybody else who's interested, to be used as pleased.

Morias:
at the moment on my test setup i use the raspberry's onboard audio output. My plan is to put the display on top of a hifiberry DAC+. If i understood things correctly the display uses different pins then the DAC+, so it should work without problems. I will however have to solder connection pins onto the DAC+. something like this: https://www.adafruit.com/products/1112

Another option would be to use some kind of expansionboard like this:
Aliexpress.com : Buy Original Raspberry Pi 2 model B/B+ Triple GPIO Multiplexing Expansion Board Multiplex Extend Module Multiplex Plate FreeShipping from Reliable plate compactor suppliers on 52pi Technology Co., Ltd | Alibaba Group

Pedorie:
It was my pleasure.
I think it will work too for other brands and types of touchscreens, but you do need to install the right drivers for the screen and touch to make it work
 
thank you very much.

TIM - May possible to add this feature, touchable screen from "freijnen" into coming release 2.4 ?

Thank you
Benkit

Hi,

I'd like to add support for some display devices but its going to take time to figure out the software and hardware. There does not seem to be any sort of standard interface for this type of peripheral.

Regards,
Tim
 
Hi,



I'd like to add support for some display devices but its going to take time to figure out the software and hardware. There does not seem to be any sort of standard interface for this type of peripheral.



Regards,

Tim


Until it is easy to add a screen to a raspberry pi with a dedicated dac I wonder how hard it would be to create a Moode viewer image for a second raspberry pi based on a standard screen / case combo.

I would be happy enough with another unit separate from the unit attached to my stereo which I could control using the tron interface.

Hope that makes sense. What I mean is the second unit effectively replaces the phone or tablet as the controller.


Sent from my iPad using Tapatalk