Image 01
profile-image

supercatfrog

Matthew Robinson
BlueamaroK

Amarok 1.x Scripts by khertz 65 comments

Ive made a change to it, below, to show the current playing track, at the top of the menu. Ive also re-ordered the menu. I appologise for the nasty, hacky code, as I dont speak spanish, tcl or the 710's AT command set.

#!/usr/bin/tclsh
#######################################################################
#
# BlueamaroK - It controls basic functions of the amaroK Player with a
# SonyEriccson mobile telephone through a bluetooth connection.
#
# This script is released under GPL free license.
#
# Pablo Chinea
# ver. 0.51 - 13/01/2006
#
#######################################################################
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#######################################################################

global CONFIGFILE
set CONFIGFILE "blueamarokrc"

#################
# Configuration #
#################
proc configurar {} {
global CONFIGFILE
global DISPOSITIVO
set outfile [open $CONFIGFILE w]
set DISPOSITIVO [ exec kdialog --inputbox "Serial device binded" "/dev/rfcomm0" --caption "BlueamaroK Configuration" ]
puts $outfile $DISPOSITIVO
close $outfile
}

######################
# Load configuration #
######################
proc cargar {} {
global CONFIGFILE
global DISPOSITIVO
if { [file exists $CONFIGFILE] } {
set infile [open $CONFIGFILE r]
set DISPOSITIVO [ gets $infile ]
close $infile
} else {
configurar
}
}

##########################
# Connect with the phone #
##########################
proc Conectar {} {
global DISPOSITIVO
global CANAL
if { [ catch { set CANAL [ open $DISPOSITIVO r+ ] } ] == 1 } {
exec kdialog --sorry "Error! Can't open $DISPOSITIVO device"
exit 1
}
fconfigure $CANAL -buffering none
fileevent $CANAL readable "Leer"
}

#######################################
# Capture the input send by the phone #
#######################################
proc Leer {} {
global CANAL
gets $CANAL entrada
puts stderr " $atcmd"
puts $CANAL $atcmd
}

#######################################
# Capture the commands sent by amaroK #
#######################################
proc iface {} {
gets stdin entrada
if { [ string match "configure" $entrada ] } {
configurar
}
}

###############################
# Execute an action in amarok #
###############################
proc action { cmd } {
exec dcop amarok player $cmd
}

###################################################
# Execute an action in amarok (with 2 parameters) #
###################################################
proc action2 { cmd1 cmd2 } {

exec dcop amarok player $cmd1 $cmd2
}

#######################
# Parsing phone input #
#######################
proc Parsear { cadena } {


global EST
global CONT
if { [ string match "OK" $cadena ] } {
global OK
set OK 1
}
if { [ string match "ERROR" $cadena ] } {
set EST 1
atsend "AT*EAID=1,0,\"BLUEAMAROK ERROR!\\0APlease, send debug output to khertz\\80gmail.com\",0"
vwait OK
vwait CONT
}
switch $EST {
0 {
if { [ string match "*EAAI" $cadena ] } {
set EST 1
kmenu 1
}
if { [ string match "*EAII: 0" $cadena ] } {
set CONT 1
}
}
1 {
if { [ string match "*EAMI*" $cadena ] } {
set val [ string range $cadena 7 end ]
if { $val != 0 } {
global MENU
eval [ lindex $MENU [ expr $val * 2 - 1 ] ]
kmenu $val
} else {
set EST 0
}
set LASTVAL $val
}
if { [ string match "*EAII*" $cadena ] } {
set CONT 1
}
}
2 {
if { [ string match "*EAII*" $cadena ] } {
if { [ string match "*EAII: 15*" $cadena ] } {
set val [ string range $cadena 10 end ]
action2 setVolume $val
} else {
set CONT 1
set EST 1
}
}
}
3 {
if { [ string match "*EAMI*" $cadena ] } {
set val [ string range $cadena 7 end ]
if { $val != 0 } {
global lista
global pag
if { ($pag != 0) } {
if { ($val == 1) } {
showplaylist -1 0
} elseif { ($val == 7) } {
showplaylist 1 0
} else {
exec dcop amarok playlist playByIndex [ expr $pag * 5 + $val - 2 ]
}
} else {
if { ( $val == 6 ) } {
showplaylist 1 0
} else {
exec dcop amarok playlist playByIndex [ expr $val - 1 ]
}
}
set CONT 1
}
set EST 1
set CONT 1
}
}
}
}

#######################
# Volume control menu #
#######################
proc volume {} {
global EST
set EST 2
set vol [ expr [ exec dcop amarok player getVolume ] / 10 ]
atsend "AT*EAID=4,2,\"Volume control\",10,$vol"
vwait CONT
}

########################
# Create the main menu #
########################
proc kmenu { sel } {


global MENU
set MENU {
"Next" "action next"
"Pause/Play" "action pause"

"Volume" volume
"Previous" "action prev"

"Backward" "action2 seekRelative -5"
"Forward" "action2 seekRelative 5"

"Mute" "action mute"
"Playlist" playlist
"Track Info" Info
"About" Acerca
}
## "Play" "action play"
## "Stop" "action stop"
set titulos ""
foreach { elem cmd } $MENU {
set titulos "$titulos,\"$elem\""
}
set long [ expr [ llength $MENU ] / 2 ]


set playing [ exec dcop amarok player title ]



set playing [ regexp -inline {\m.{1,11}$} $playing ]

#regsub -all {[^qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM1234567890]} $playing "" playing


atsend "AT*EASM=\"$playing\",1,$sel,$long$titulos"
vwait OK


atsend "AT*EAST=\"$playing\""
atsend "AT*EAM=\"$playing\""



}

#########################
# Generate the playlist #
#########################
proc genlist { fich } {
set infile [open $fich r]
while { [ gets $infile cadena ] >= 0 } {
if { [ string match "* titulo
}
if { [ string match "**" $cadena ] } {
regexp "(.*)" [ string trim $cadena ] -> artista
}
if { [ string match "* 0 } {
set elem "$artista - $titulo"
} else {
set elem $titulo
}
lappend lista "$elem"
}
}
close $infile
return $lista
}

####################
# Get the playlist #
####################
proc playlist {} {
global EST
global lista
if { [ exec dcop amarok playlist getTotalTrackCount ] == 0 } {
atsend "AT*EAID=1,0,\"Playlist empty\",20"
vwait OK
vwait CONT
} else {
set EST 3
set lista [ genlist [ exec dcop amarok playlist saveCurrentPlaylist ] ]
exec dcop amarok playlist shortStatusMessage "Default Playlist saved by BlueamaroK"

set pos [ exec dcop amarok playlist getActiveIndex ]
global pag
if { $pos == -1 } {
set pag 0
set offset 0
} else {
set pag [ expr $pos / 5 ]
set offset [ expr $pos % 5 + 1 ]
}
showplaylist 0 $offset
}
}

##########################
# Show the playlist menu #
##########################
proc showplaylist { inc offset } {
global lista
global pag

set pag [ expr $pag + $inc ]

set longit [ llength $lista ]
set ini [ expr $pag * 5 ]
if { [ expr ($longit - 1) / 5 ] == $pag } {
set fin [ expr $longit - 1 ]
} else {
set fin [ expr $ini + 4 ]
}

set titulos ""
set long [ expr $fin - $ini + 1 ]

if { $offset } {
set sel $offset
} else {
set sel 1
}

if { $pag != 0 } {
set titulos "$titulos,\"\""
set long [ expr $long + 1 ]
set sel [ expr $sel + 1 ]
}

foreach elem [ lrange $lista $ini $fin ] {
set titulos "$titulos,\"$elem\""
}


if { [ expr ($longit - 1) / 5 ] != $pag } {
set titulos "$titulos,\"\""
set long [ expr $long + 1 ]
}

set npag [ expr $pag + 1 ]
set tpag [ expr ($longit - 1) / 5 + 1 ]

atsend "AT*EASM=\"Playlist ($npag/$tpag)\",1,$sel,$long$titulos"
vwait CONT
}

##########################
# Show track information #
##########################
proc Info {} {
set nombre [ exec dcop amarok player nowPlaying ]
set duracion [ exec dcop amarok player totalTime ]
set info "* $nombre\\0A* $duracion"

set bitrate [ exec dcop amarok player bitrate ]
set samplerate [ expr [ exec dcop amarok player sampleRate ] / 1000 ]
set info "$info\\0A* $bitrate - $samplerate Hz"

set fichero [ exec dcop amarok player path ]
if { [ file readable $fichero ] == 1 } {
set tipo [ string trim [ exec file $fichero | cut -d: -f2 ] ]
set info "$info\\0A* $tipo"
}
atsend "AT*EAID=14,2,\"Track Info\",\"$info\""
vwait CONT
}

#######################
# Show "About" dialog #
#######################
proc Acerca {} {
set a_pro "* BlueamaroK ver. 0.51"
set a_aut "* Pablo Chinea "
set a_web "* http://www.khertz.net/"
set a_lic "* This script is released under GPL free license."
set acerca "$a_pro\\0A$a_aut\\0A$a_web\\0A$a_lic"
atsend "AT*EAID=14,2,\"About\",\"$acerca\""
vwait CONT
}

#############################
# Initialize the connection #
#############################
proc IniCon {} {
atsend "ATZ"
vwait OK
atsend "ATE=0"
vwait OK

#title for menu
atsend "AT*EAM=\"Amarok\""
vwait OK
atsend "AT*EAID=1,0,\"Connected to Amarok\",20"
vwait OK
vwait CONT
atsend "AT*EAST=\"Amarok\""
vwait OK
}




#################
# Main function #
#################
proc main {} {
global EST
set EST 0
cargar
Conectar
IniCon
fileevent stdin readable "iface"
vwait BUCLEINF
}

main

- Oct 03 2006
BasKet Note Pads

Utilities by kelvie 347 comments

i'd like to beable to send basket items to kopete contacts, email contacts and 'browse'

the same as konqueror > right click a file > copy to * - May 26 2005
KShutdown

Utilities by kdt 80 comments

you need to go into configure > actions and change shutdown to /sbin/poweroff (or something like that) and reboot to /sbin/reboot or something like that) - Feb 28 2005
Discover KDE 3.3

Various Stuff by philipacamaniac 5 comments

If you dont like shiney graphics, turn them off. There's nothing to force you to complain about somebody elses hard work, just because you dont want to use it. - Nov 16 2004
Kuake

System Software by epoch 14 comments

great software, love it, although i'd like to beable to split it into two panes at the bottom of my screen, like this (if it shows up right):

----------
| |
|________|
|____|___| - Nov 14 2004