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
Technical-Solution
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
close

on 04th April 2007 / by webmaster
Linux is the epitome of the FLOSS model. Technical Solution Linux installation Leave a reply Your email address will not be published. Required fields are marked * Dewey J. Corl (not verified) access_time 15 Jul 2020 - 14:41 Linux is not ready for the general public! (I am a Ubuntu user). For proof, 1. try to simply print labels on a Dymo label printer. It takes a LOT of work to get to the ease of label printing already available in Windows and Mac. 2. try syncing a modern Palm based PDA. Yes, jpilot and others will sync the main data, but pictures and midi files do not get transferred without a lot of extra setup. These are examples of applications that are not ready for the general public. Since an operating system only supports applications, Linux is not ready to be a common desktop for the general public. While we are waiting for the applications to catch up, keep up the good work!! Anoop John (not verified) access_time 15 Jul 2020 - 14:41 Dewey Yes you may be right. But these are not applications that a common man would use. A common man would use one of these applications - Internet browser, Chat Client, Email Client, Document Writer, Presentation Creator, Spreadsheet Editor, Movie Viewer, Music Player, CD/DVD Writer. Both examples you cited are more specific applications that only a small percentage of the whole population uses. It will take time before those hardware vendors identify the need from their perspective to address the Linux community. Krishnadas (not verified) access_time 15 Jul 2020 - 14:41 Dear Mr Anoop, Thank you very much for the free installation of LINUX done in my PC. I am getting immersed in the LINUX and seeing the versatility. To my surprise, I am able to read one of my old backup CD(wherein lot of my valuable file exist) done in DIRECT CD wizard (a custom cd writing software of Easy Cd creator in WIN98) which could not be read in XP. Installation of old version of easycd creator/direct cd program was not possible in XP. I thought that possible i lost all data. Very pleasant start! Srikanth N. S. (not verified) access_time 15 Jul 2020 - 14:41 Hi Anoop, My friend is thrilled with Ubuntu. One of his grouses with windows was that after OS installation, everything else is to be installed separately which is a real headache. WHereas if u install Linux, everything is installed as a package and he is thrilled to bits! Let linux installation spread in Trivandrum and your service in this direction is highly appreciated. Kepp up the good work Regards. PDA Freak (not verified) access_time 15 Jul 2020 - 14:41 Is it possible to install linux on a packardbell notebook ? Pagination Current page 1 Page 2 Next page Next › Last page Last » 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.