Archive for the ‘Music’ Category

Play your entire music collection - Mplayer One Liner

Saturday, April 16th, 2011

Sometimes just plain lazy, and want just to play music. Run this command in the background (ALT+F2) or in a terminal for playback of all your mp3/ogg/m4a/wma, shuffled, looped, normalised. What’s nice about this is that the shuffle algorithym does a good job and with a large collection of music you don’t get repeats. I found that trying the same thing with vlc meant the shuffle was  always the same, and so you always started with the same music. :( Anyway the one-liner:

find ~/Music \( -iname “*\.mp3″ -o -iname “*.m4a” -o -iname “*.ogg” -o -iname “*.wma” \) -exec mplayer -nocache -af volnorm -shuffle -loop 0 ‘{}’ + &

Change “~/Music” to suit.

Even better put this in a script, and link to a keyboard shortcut, or add to your startup?

Now running the one liner from a terminal takes a bit of stopping, you’ll need to CTRL+C a couple of times in quick succession to close find then mplayer. Or you can run another one-liner:

killall -15 find mplayer

If you run the command from a script, you’ll have to shut down the script first, and then kill off the running instances of find and mplayer. Best to also do this from a script as well. Say the script you use to run is called singles.sh, let’s create another called endsingles.sh which contains:

#!/bin/bash

killall -15 singles.sh
killall -15 find
killall -15 mplayer

I am sure someone clever could bind this all together in one script, based upon a keyboard shortcut toggle or something…

Jinamp Party Piece

Saturday, February 26th, 2011

Jinamp Party Piece

Ok, daughter having birthday party, kicking us out of the house for the evening. Last year, I set her up with Audacious on the htpc so that she and her guests could chose music to play, with a couple of backup options of using xbmc or a DVD full of mp3s. This year we have a new machine running as htpc, no DVD drive. Also, daughter just wants a shuffled playlist to run, with no intervention.

A few weeks ago I was mooching about on KMandla’s new wiki of CLI apps, and came across jinamp , which is a sort of background player. What it does is takes the feed of a directory or playlist, shuffles it, then sequences it to a player of its or your choice, then disappears off into the background.

So I built up a playlist using audacious, called it pop.m3u and saved it to a shared place on the network. I needed to tidy up this list to just have file paths and names so:

sort pop.m3u > pop.lst

*.lst is the default file format for playlists with jinamp. Next I just opened up pop.lst and deleted all the EXTINF lines, which were now nicely sorted to the top. So now the playlist contents looked like this:

/path/to/song1.mp3
/path/to/song2.mp3
/path/to/song3.mp3

Order doesn’t matter because it is going to get shuffled anyway ;)

So downloaded and installed the latest (and pretty old) version of jinamp

sudo dpkg -i jinamp_1.0-1.i386.deb

I also had to install mplayer, as I was going to use this as my player:

sudo apt-get install mplayer

Added just one line to mplayer’s ~/.mplayer/config file for now:

af=volnorm

in the hope that this would help to normalise sound levels (seems to do something)

Right ready to test now, here is the basic command to get it running:

jinamp -p /usr/bin/mpayer /path/to/pop.lst

There is a little pause, and then music starts playing, you are back at the command prompt, and can no longer interact with the program. If you look in htop, you will see an entry for jinamp and also one for mplayer playing the file.

I set up the htpc with a fullscreen terminal, which would just serve to confuse (no fiddling) and amaze (how cool and geeky!) 17 year olds :) Had to run this with X, as for some reason I can’t get a VT over hdmi.

But of course you need to be able to interact with jinamp, to stop it (it will just keep on going!) or to skip to the next song. You might also want to display the title and artist of the current playing song as well. This is where jinamp-ctl comes in.

jinamp-ctl stop

will stop the thing running and close the player.

jinamp-ctl next

will move you to the next song on “jinamps” list.

jinamp-ctl query

will show you the name of the currently playing song (along with its full path!)

So I set about figuring out how to start the player, and then show the name of the currently playing song in the middle of the screen, without the mp3 extension, no cursor or mouse cursor, in a lovely cyan colour with a black background. I needed a script!

To remove the terminal cursor you have to type:

setterm -cursor off

To remove the mouse cursor, the easiest solution I found was to install “unclutter” and then run it, removes the idle cursor from the screen after 5 seconds by default. Further usage and investigation shows that unclutter runs at start up so if you like having it in your session, you don’t need the command. If you want to choose when to start unclutter, then edit the /etc/default/unclutter file and change true to false.

sudo apt-get install unclutter

unclutter

To change the colour of the screen text I needed “tput” which is already installed by default.

tput setaf 6

makes text cyan

tput setab 0

makes the background black (already is but useful to know)

tput bold adds

bold to the text to make it stand out more.
More on this here

Next was to strip the filename back to you the Artist and Title from the output of jinamp-ctl query. I did this by piping jinamp’s output into xargs and basename as follows:

jinamp-ctl query | xargs -0 -n1 -imp3 basename mp3 | cut -d”.”

It took a fair bit of googling to find all the elements required for this :)

Then I needed this output to update regularly. Too tricky for me to figure out what was required when the song actually changed, so I just went for a routine that fired every five seconds:

sleep 5

Finally, the solution to centre the text output on the screen. This takes a bit of trial and error, I am sure it can be figured out programatically rather than adjusting numbers, but for my purposes, this worked. The htpc screen is running at 800×600 (because the htpc is also linked to another older TV that can’t cope with more) so a terminal at full screen has @ 80 columns and 30 lines. I found that:

perl -e ‘print “\n”x10′;

added enough blank lines, and then piping all the output through to:

sed  -e :a -e ’s/^.\{1,57\}$/ & /;ta’

put the text more or less in the centre. ( I also set terminal font size to 16 ). Life is too short for me to learn and understand sed :)

So the final script called jinamp.sh looks like this:

#! /bin/bash#hides cursor
setterm -cursor off &

#hides mouse cursor after 5 seconds
unclutter & # (only needed if you haven’t rebooted)

#starts jinamp with named playlist

jinamp -p /usr/bin/mplayer “/media/music/burn/pop.lst”

#displays playing file every five seconds when jinamp is running

tput setaf 6;
tput setab 0;
tput bold;
while [ 1 ]; do
jinamp-ctl query | xargs -0 -n1 -imp3 basename mp3 | cut -d”.” -f1 && perl -e ‘print “\n”x10′; sleep 5; done | sed  -e :a -e ’s/^.\{1,57\}$/ & /;ta’

This is all fine, but daughter might wish to move to the next song. To save her fiddling about at the htpc with wireless mini keyboards and remotes, I simply set her up with a putty ssh session into the htpc so that she could type jinamp-ctl next.

Party is tonight, so we’ll see how well it goes. Had the thing running all morning without a hitch, but will have to write instructions in case of power failure, or some oik unplugs the htpc, etc…..

Linux - Listen to Microphone on remote PC

Sunday, December 26th, 2010

Due to the festive season there was a need to contact relatives in far flung places. Of course I hadn’t done any preparation, so things didn’t work as I wanted. I plugged a PS2 Eyetoy into my htpc, and installed Skype. Was pleased to see the video worked off the bat, but when contacting my first relly, I could see and hear them, they could see me, but could not hear me. The mic on the Eyetoy wasn’t configured correctly. Due to my work with special needs kids, I put my sign language (Makaton) skills (limited!) to good use, and we had a fun conversation as I taught my rellies sign language using sign language :)

Anyway set about reconfiguring my htpc to get the mic working later that evening. It’s a Ubuntu 10.10 setup, so I removed pulse audio, and got back to a basic alsa setup. (Note: my main PC is set up the same way) I did all the setup via ssh from my main desktop. Needed a way to test my microphone was working:

arecord -l

gave the the number of my device:

card 1: Namtai [EyeToy USB camera Namtai], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

I then tracked down via google a command that with some modification allowed me to listen to the microphone on the speakers on my main PC (in a another room). I put my smartphone next to the eyetoy, and set it to play an audiobook I had on it. Ran back to my study and ssh’d into the htpc. Once there I had to run the command, which included ssh’ing back to my main PC (bet that would confuse 2 windows PCs if you tried it!) Command all on one line:

 arecord -f dat -D plughw:1,0 | ssh -C bimma@10.10.10.10 aplay -f dat

and blow me, the sound of my audiobook being “listened to” by the microphone came through loud and clear on my main PC speakers

Key things: getting the device right, the arecord -l command gave the information of card 1 and device 0, which translates to plughw:1,0 (the -D option denotes the device for arecord to listen to), and -f dat indicates the format the sound will be recorded in and relayed to the remote PC. Have a good read of man aplay, for more info.

Now to try things out on a different relly tomorrow ;)

A Christmas Chune for You

Wednesday, December 22nd, 2010

Heard this on the radio the other day, drives SWMBO mad

Spike Jones’ My Birthday Comes on Christmas

My Birthday Comes On Christmas

Mp3 playlist script - for current directory and sub folders

Thursday, February 18th, 2010

Making mp3 playlists, a “simple” script

#!/bin/bash

touch ${PWD##*/}.m3u
export IFS=$’\n’
for i in $(find $1 -name “*.mp3″ -type f)
do
echo “$i” |sed ’s/..\(.*\)/\1/’ >> ${PWD##*/}.m3u
done

shuf ${PWD##*/}.m3u > ${PWD##*/}2.m3u
shuf ${PWD##*/}2.m3u > ${PWD##*/}.m3u
rm ${PWD##*/}2.m3u

You can leave out the last three lines if you don’t want to shuffle the list.

There is probably improved/easier code than this but it works for me.

To use, simply copy the code into a text file, save with a name of your choice, and make the file script executable. Put the file in your path, and then run in the directory you want to make a playlist from. it will work on all sub directories of that folder.

Get Some Dope? Nope?

Sunday, March 29th, 2009

Been a while since I put up any music, here is one that rocks my boat from Dope’s new album No Regrets

Dope - Nothing For Me Here

Those End Of Film Songs

Saturday, February 14th, 2009

Those End of the Film Songs

Here is a set of what you might call an eclectic mix of songs found playing
at the end of feature films over the credits. Perhaps there are others worth adding? (more…)

Celine Dion - Taking Chances

Saturday, November 10th, 2007

We like this one too

Celine Dion - Taking Chances

Leona Lewis - Bleeding Love

Sunday, October 21st, 2007

Quite like this one

Leona Lewis - Bleeding Love

BuckCherry - Everything

Tuesday, October 2nd, 2007

Just found this lot, a good rock sound from 2005

BuckCherry - Everything