Browse Source

mptk: highlight the button with current song's score

master
Maxim Likhachev 5 years ago
parent
commit
f6fe5b6d57
  1. 36
      scripts/mptk

36
scripts/mptk

@ -12,29 +12,51 @@ array set buttons { @@ -12,29 +12,51 @@ array set buttons {
next 怜
}
set used_ratings {1 2 3 4 5 5+}
proc mpc {args} {
exec mpc {*}$args
}
proc current_file {} {
lindex [split [exec mpc -f {%file%}] "\n"] 0
set filename [file join $::music_directory [lindex [split [exec mpc -f {%file%}] "\n"] 0]]
}
proc rate {rating} {
set filename [file join $::music_directory [current_file]]
set filename [current_file]
exec mid3v2 --delete-frames=COMM $filename
exec mid3v2 --COMM $rating $filename
hl_rating $rating
mpc update
}
proc current_rating {} {
set filename [current_file]
set tags [split [exec mid3v2 [file join "/mnt/DATA/Музыка" $filename]] "\n"]
lindex [split [lsearch -inline -glob $tags "COMM*"] "="] end
}
proc hl_rating {rating} {
foreach r $::used_ratings {
if {[winfo exists .rating.$r]} {
set c [expr {$r == $rating ? {red2} : {black}}]
.rating.$r configure -activeforeground $c -foreground $c
}
}
}
proc update_status {} {
set ::mpd_status [mpc]
after 500 update_status
}
update_status
hl_rating [current_rating]
after 1000 update_status
}
frame .status
frame .rating -pady 10
@ -44,7 +66,7 @@ pack .status -fill x -expand true -padx 20 -pady 20 @@ -44,7 +66,7 @@ pack .status -fill x -expand true -padx 20 -pady 20
pack [label .status.current -font {Sans 20} -textvariable ::mpd_status]
pack .rating
foreach rating {1 2 3 4 5 5+} {
foreach rating $::used_ratings {
pack [button .rating.$rating -text $rating -font {Sans 60} -width 2 -command "rate $rating"] -side left
}
@ -53,6 +75,8 @@ foreach btn {prev toggle next} { @@ -53,6 +75,8 @@ foreach btn {prev toggle next} {
pack [button .control.$btn -text $buttons($btn) -font {Sans 80} -width 4 -command "mpc $btn"] -side left
}
update_status
bind . <KeyPress-Control_L><KeyPress-q> exit
bind . <KeyPress-Control_R><KeyPress-q> exit

Loading…
Cancel
Save