Monday, October 3, 2016

A collection and player for Indian Classical Music Bandish

Some years ago, around 2010, i had added an "Indian Classical Music" section to my site
I used ascii letters and symbols for the notation. e.g. SrRgGmMPdDnN.
A full notation help is available here :
The java midi api was used to create midi files for the bandish( compositions) and play them.
However, with the restrictions on applets and Java Web start in browsers for security reasons, support for the java player in browsers became more and more difficult.
Now unlike reading/writing local files or executing a program, outputting music is not usually a security concern.
The relatively recent web audio api, addressed this issue and made playing audio thru JavaScript possible. There are many frameworks like Tone.js, which allow us to play tones thru javascript. I have moved the bandish-payer on my site for indian classical music from applets to Tone.js. Currently meend(glide) and andolan, which were covered in the java version, are not yet available.
The "Play" link will invoke the player. Here is a link to a bandish :

Monday, July 4, 2016

Converting a pdf to csv using linux shell script

linux script to extract data from pdf and create a csv. The regular expressions for sed are rather different from the Perl like ones i am used to in java. So \d is not allowed, + needs to be escaped, etc.

Below, we iterate thru pdfs, use pdftk to get the uncompressed version that has text, use strings to extract string data, use tr to remove newlines, apply sed on it to extract particular fields that we want, assign those to variables, and echo the variables to a csv file.

rm pdf.csv
for FILE in *.pdf
  echo $FILE
  pdftk "$FILE" output - uncompress | strings | grep ")Tj" | tr '\n' ' ' | sed -e 's/)Tj /) /g'  > temptocsv.txt
  AMOUNT=`sed -e 's/.*(Rs \:) \([0-9]\+\).*/\1/' temptocsv.txt`
  CHLDATE=`sed -e 's/.*(Date of) (challan :) (\([^)]\+\)).*/\1/' temptocsv.txt`
  SBIREFNO=`sed -e 's/.*(SBI Ref No. : ) (\([^)]\+\)).*/\1/' temptocsv.txt`
  CHLNO=`sed -e 's/.*(Challan) (No) (CIN) \(.*\) (Date of).*/\1/' temptocsv.txt`