WINDOWS.md 5.0 KB

cmus-scripts/windows

Cmus on Windows??

Yup, that's right. Cmus can be built and ran on Windows under Cygwin. It's not exclusive to Linux. I will not cover the installation of cygwin, or the steps required to build/install cmus.
But I may add it to the wiki later, if anybody has any interest.

All of the mandatory build dependencies for cmus are available in Cygwin.
Most of the optional dependencies are available too.

I think the only features I'm missing in the Windows version ATM is AAC/m4a playback. But mp3, wav, ogg all work fine. Streaming online radio also works!


Running and controlling cmus in Windows

I usually run cmus in a cygwin terminal in a tmux session on my Windows PC at work.
The bash aliases and the nowplay script (in the scripts directory) allow me to control playback from any cygwin terminal window.

The windows directory in this repository contains some additional .bat files, which I have assigned to some hot-keys, allowing me to control cmus (running in a cygwin terminal) from the desktop on my Windows PC at work.


Installing nowplay and the bash aliases

This is the same procedure as Linux:
Copy the nowplay script to anywhere on your path in cygwin.
I have it in my personal bin directory in my cygwin home dir (~/bin/), but you could put it into /usr/local/bin, or /usr/share/bin, or wherever! As long as it is somewhere on your path.
Then you can edit your .bashrc and set up some aliases for cmus-remote to control playback and view information from nowplay (see aliases file in ../scripts for some examples)


Installing the .bat files

The batch files need to be copied to a directory in the Windows start-menu.
On my Windows 7 work PC, I have the batch files installed to:
C:/Users/username/AppData/Roaming/Microsoft/Windows/Start Menu/\_hotkeys/

Where _hotkeys is a directory I created.

For some reason, if you create a shortcut outside of the start-menu and assign a hot-key to it, it will only persist for the rest of that desktop session. The next time you log-in, the keybind will not work. If you open the properties of your shortcut - your keybind is still there, it just doesn't work.

This issue perplexed me for a while. After a bit of digging online, I eventually discovered that hot-keys will only get picked up on startup if they are in one of the startup folders - so after a bit of experimentation, the best solution I came up with was putting the batch files and the shortcuts into a sub-directory in the "Start Menu".

IMPORTANT NOTE:

You will need to check each .bat file and ensure that the path to the cygwin/bin direcotry reflects your setup.
So, in line 3 of each script - the parameter to chdir must contain the correct path to your cygwin/bin directory. On my work PC - cygwin is installed to c:/cygwin64/. So I use C:/cygwin64/bin

If you have a 32-bit install of cygwin on z:, you would change the path in line 3 of each script to:
z:/cygwin/bin


The final step is:

Create some shortcuts and assign hot-keys.

You will need to right-click each .bat file and select "Create Shortcut" to create a shortcut to the batch file.
Then right-click on each shortcut and select 'properties'.
In the field labelled "Run:" select "Minimized" - this will ensure that the terminal that briefly pops up to control cmus will start minimized and won't get in your way.
Then select the field labelled "Shortcut key:" and press the key combo you want to use to fire-off the script.

I currently have each .bat file mapped to the following shortcuts:
ctrl+alt+z -> prev.bat = previous track
ctrl+alt+x -> stop.bat = stop
ctrl+alt+c -> pause.bat = pause/resume
ctrl+alt+v -> play.bat = play
ctrl+alt+b -> next.bat = next track

So the keys correspond loosely with the default keys for cmus (zxcvb - albeit with ctrl+alt in front of them!)

With the batch files and shortcuts with hotkeys set up, you can now control cmus from the desktop.
The only minor caveat with this system is that whenever you use one of the keybinds, it pops up a minimised window, which briefly steals focus. So whatever window you were working in before will lose focus. And you have to re-select it again. I usually have the mouse in or near the window I'm working in, so when I hit a keybind and the program I was working in loses focus, it's just takes a quick mouse-move and a click, Or a quick alt-tab to regain focus.

The focus stealing aspect can be annoying sometimes, but if you are working and that really annoying song comes on that you hate - or someone comes in to talk to you. Rather than fumbling with your mouse to select the window running cygwin/cmus and hit skip, or pause - you can just hit your shortcut and the corresponding action will be performed.

It's not a perfect system, but it works well enough for me!