Created
March 17, 2025 13:48
-
-
Save wilenius/ba83fc486af311e099f8e6bc76a1d65e to your computer and use it in GitHub Desktop.
cmus remote control with midi, tmux notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Replace "<client name>" with your actual MIDI client name | |
CLIENT_NAME="Faderfox UC4" | |
# Function to convert seconds to HH:MM:SS format | |
convert_seconds_to_hhmmss() { | |
local total_seconds=$1 | |
local hours=$((total_seconds / 3600)) | |
local minutes=$(( (total_seconds % 3600) / 60 )) | |
local seconds=$((total_seconds % 60)) | |
printf "%02d:%02d:%02d" $hours $minutes $seconds | |
} | |
# Function to get the current position in the audio file | |
get_current_position() { | |
local position=$(cmus-remote -Q | grep 'position ' | awk '{print $2}') | |
echo $(convert_seconds_to_hhmmss $position) | |
} | |
# needs logic that reloads length when song is changed | |
get_song_length() { | |
local length=$(cmus-remote -Q | grep 'duration ' | awk '{print $2}') | |
echo $(convert_seconds_to_hhmmss $length) | |
} | |
length=$(get_song_length) | |
aseqdump -p "$CLIENT_NAME" | | |
{ | |
# Ignore first two output lines of aseqdump (info and header) | |
read | |
read | |
while IFS=" ," read src ev1 ev2 ch label1 ctrl_no label2 ctrl_value rest | |
do | |
case $ctrl_no in | |
85) | |
case $ctrl_value in | |
127) cmus-remote -u ;; | |
esac | |
;; | |
58) | |
case $ctrl_value in | |
63) cmus-remote -k -5 ;; | |
65) cmus-remote -k +5 ;; | |
66) cmus-remote -k +10 ;; | |
67) cmus-remote -k +20 ;; | |
62) cmus-remote -k -10 ;; | |
61) cmus-remote -k -20 ;; | |
*) echo "Controller 58, other value: $ctrl_value" ;; | |
esac | |
# Get the current position and display it using tmux | |
current_time=$(get_current_position) | |
tmux display-message "Current time: $current_time / $length" | |
;; | |
*) echo "Other controller";; | |
esac | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment