Script to play MIDI files in Banshee 2.0 in Ubuntu without going into an infinite loop
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY Anoop John
6 years ago
Ubuntu
0 comments comment

I was trying to get a list of MIDI files play in banshee 2.0 in an old computer. The system had Ubuntu 11.04 and banshee was able to play MIDI files except that it was not able to detect the end of each track and continued playing the same track with silence as the only output and infinitely playing the same track. So whenever there was a long silence I had to manually change to the next track. I did that a few times but then decided to write a small script to solve the problem.

Banshee supports passing commands via the command line. It also supports querying information about the currently playing track from the command line. However it was not able to get the length of the currently playing track from the command line. For this I had to use another utility (smfsh - sudo apt-get install smf-utils)

Now smfsh is an interactive command-driven frontend to libsmf, useful for modifying MIDI files by hand and for querying information about MIDI files. Because it opens an interactive shell I had to write a small input file that passes the required command to the shell and then exit the shell.

The complete script is as follows. This is released under GNU/GPL v3 and is available from the zyxware github account under the misc-utils repository.

#!/bin/bash

debug=0

# Infinite loop
while :
do
  # Get the path to the current file
  cur_file=`banshee --query-uri | cut -c 13-10000`
  # Get the length of the current track using smfsh since banshee is not 
  # able to stop at the end of the midi files
  cur_track_length=`smfsh $cur_file &1 | grep Length | awk '{print $4}' | cut -d. -f1`
  # Get the current position in the current track
  cur_track_pos=`banshee --query-position | awk '{print $2}' | cut -d. -f1`
  if [[ $debug -eq 1 ]]; then
    echo "Playing $cur_file at $cur_track_pos / $cur_track_length seconds"
  fi
  if ! [[ "$cur_track_length" =~ ^[0-9]+$ || "$cur_track_pos" =~ ^[0-9]+$ ]]; then
    banshee --next
  else
    # If banshee has been playing for longer than the duration of the current track then 
    # play the next track
    if [[ $cur_track_pos -gt $cur_track_length ]]; then
      banshee --next
    fi
  fi
  sleep 5
done

You will need to create an in.txt file in the same folder with the following contents as well

length
quit

You can save the text file as play-midi.sh or something like that and then run it in the background and that should be all. The script will check if banshee has overrun the currently played midi file and if so switch to the next track.


RELATED ARTICLE

/themes/custom/zyxpro_light/images/placeholder.png
more_horiz
close

on 20th April 2007 / by webmaster
Linux has been growing in leaps and bounds in terms of internationalization. Linux Malayalam Open Source Ubuntu Leave a reply Your email address will not be published. Required fields are marked * Ranjith Antony (not verified) access_time 21 Oct 2019 - 13:33 Everything is fine an dandy. However, to read those websites which doesn't support unicode fonts you have to install padma firefox extension . Those websites include all malayalam newspaper websites including, deepika, manorama, keralakaumudi etc. These websites only support truetype fonts. TrueTypes are glyphs matching a malayalam character but doesn't have a hex code assigned to it. They use ASCII character set but with a different glyph. Just to read malayalam, you only need to perform the first 3 steps in Peringodan's blog, in addition to the hacks thats been explained in this blog post. PS: Its so funny; a tutorial to explain how to install malayalam read and write support is written in malayalam. Thats what called a chicken and egg problem. Cherry (not verified) access_time 21 Oct 2019 - 13:33 I’d like to point out a couple of things: a) Malayalam support is not an Ubuntu thing or a Linux thing… I am running NetBSD -current on my laptop with x.org and I can type malayalam. Learning the key combinations is very easy and intuitive… it just requires attention and commitment. I learnt it in about a week and something. b) Mangleesh support for TeX has been around for a while. The TuX group in Trivandrum and specifically A.J.Alex have worked on very good quality latex support for malayalam. See: sarovar.org Just to set the record. Cheers, Cherry. vimal access_time 21 Oct 2019 - 13:33 Ready to use packages to support malayalam in Ubuntu 7.10 and Debian GNU/Linux Etch is available at http://malaylam.web4all.in . Add new comment
/themes/custom/zyxpro_light/images/placeholder.png
more_horiz
close

on 05th May 2007 / by webmaster
BSNL is one of the leading broadband providers in India. Hardware Linux Networking Ubuntu Leave a reply Your email address will not be published. Required fields are marked * Abhi (not verified) access_time 21 Oct 2019 - 09:52 Hello, I am trying to connect to my D-link DI-614 wireless router to the my BSNL ADSL broadband modem DB108. My PC is currently connected to the modem via an ethernet link. Instead, I established a two-way connection in the following way: 1) Router - modem via ethernet cable. 2) PC - Router via an ethernet cable. However when I do this, my PC is not able to connect to the internet. I am wondering if anyone can help me out with this. Subhadeep (not verified) access_time 21 Oct 2019 - 09:52 Thankx for this i was in a real problem connecting to the net via broadband on BSNL. Thankx again man u r life saver... Add new comment
/themes/custom/zyxpro_light/images/placeholder.png
more_horiz
close

on 08th May 2007 / by webmaster
A majority of people still look at Linux as something where you have to type everything in consol Linux Ubuntu Leave a reply Your email address will not be published. Required fields are marked * Manoj Mathai (not verified) access_time 21 Oct 2019 - 14:43 hi, read your comment on slashdot. thats how i got here. i think ubuntu is a gr8 linux distro and all it needs is good support and lots of GUI tools to make it smoooth to install and use. if each linux enthusiast can get atleast 5 ppl to atleast try ubuntu or any other distro, i think it would be of gr8 help. anyways, what role does linux play in your company ? Jayson (not verified) access_time 21 Oct 2019 - 14:43 I stumbled upon your blog and I definitely will give you a ring when I need something for my PC! Anoop John (not verified) access_time 21 Oct 2019 - 14:43 Manoj, We sell PCs and Peripherals. We give linux as the preloaded operating system in all the systems we sell. Ubuntu is our default choice unless the customer requests another distro. We also have a software development division. All the systems used for software development are running either ubuntu or xubuntu. We are also providing free linux assistance to customers. These are some ways we are trying to contribute to the Linux community. Add new comment
Leave a reply
Your email address will not be published. Required fields are marked *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.