CammillaDSP - Controlling from shell script

Hi, I’d like to control an instance of Camilladsp from shell commands (Mac). I‘m thinking this might be done via the websocket interface using curl (?) commands (as I do with my MOTU interfaces) just not sure of the syntax. I’ve looked at the ”Controlling Via Websocket” and pyCamillaDSP documents just not sure how to wrap into a shell command. A few simple examples of using say the GetFaderVolume and SetFaderVolume commands might give me a good start.

Cheers, Louis
 
Last edited:
There are probably hundreds of questions "like these " . Multiply with hundreds of long topics. This forum would be a totally mess if everyone would do like this. Henrik will have a hard time answering everything if all of it is separated. Searching within a topic also looses its function. Maybe one topic as support/help and another questions regarding functionality could work? Speaking as a mod on another forum.
 
There are presently 247 pages in the “thread” you referenced. it’s way beyond me to follow who’s saying what to whom.

I believe Henrik has indicated he doesn’t want the distraction of administering a CamillaDSP specific sub-forum which I can understand and respect.

“PC Based“ cuts a wide swath so I chose to use separate threads with “CamillaDSP“ preceding the subject to make it easy to search (or ignore).

Don‘t know the answer but as more folks learn about how solid and useful Camilla is, a single thread seems all but unusable. Perhaps the moderator(s) could chime in and offer some guidance.

Cheers, Louis
 
  • Like
Reactions: 1 user
Hi Henrik,

Method 1:

Some further searching around web sockets and the command line came up with this idea. Doesn’t seem very elegant but it works:

$ echo '"GetVolume"' | websocat ws://127.0.0.1:1234
{"GetVolume":{"result":"Ok","value":-20.0}}

$ echo '{"SetVolume": -30}' | websocat ws://127.0.0.1:1234
{"SetVolume":{"result":"Ok"}}

$ echo '"GetVolume"' | websocat ws://127.0.0.1:1234
{"GetVolume":{"result":"Ok","value”:-30.0}}

So I could build an adjust_volume shell script around that.

If there are any websocat gurus out there maybe there is a better (or at least more elegant) way to use websocat than echo through a shell pipe?



Method 2:

I’ve been playing with your pyCamilla and following the example instructions (with a fair amount of trial and error) I have an adjust_volume.py doing what I want from a shell with an activated venv. I have never really understood python’s environments and how to generalize their scope while not having it trip all over itself. In this case I’ve not been able to figure out how to run this python script as a single shell script command from outside the activated venv. Sorry, that wasn’t very clear - that lack of understanding thing. The references I’ve found on this so far seem to assume a level of familiarity with things python which I don’t really have. Not your thing to teach me python (mac) but any guidance greatly appreciated.

Just spent hours down the rabbit hole of pyinstaller trying to make a one-file executable from within the activated venv but even with
--includehidden=camilladsp (and variations) the build succeeds without complaint but the resulting executable seems to still look for it externally:

$ ./dist/adjust_volume 1234 -2
Traceback (most recent call last):
File "adjust_volume.py", line 2, in <module>
from camilladsp import CamillaClient
ModuleNotFoundError: No module named 'camilladsp'
[87620] Failed to execute script 'adjust_volume' due to unhandled exception!
Exit 1

Python and I are not yet friends...



The application:

I use several of an old product called a Griffin PowerMate (basically a direction sensitive USB rotary knob/button/indicator) as physical volume controls/mute toggles. In my setup, each increment of rotation fires off the appropriate shell command (presently json commands via curl to my MOTU networked interface) to incrementally raise or lower a fader value. For good responsiveness, latency through the command chain counts. I’d like to change this to have it control Camilla loudness filters instead. By the time Method 1 is fleshed out with bounds checking and such I don’t know which method would yield better results. I’ll cobble something together and run some tests.

Cheers and thank-you, Louis
 
Last edited:
Update:

Wrote an (ugly) bash script around websocat and did a very unscientific comparison of speed with my python script in venv. Non-integer math in shells is a pain!

Python: around 19 per sec
---------------
bash$ time for run in {1..19}; do python adjust_volume.py 1234 -1; done
real 0m1.008s
user 0m0.799s
sys 0m0.145s


bash-websocat: about 54 per sec
----------------------
bash-3.2$ time for run in {1..54}; do ./adjust_volume.sh 1234 -1; done
real 0m1.008s
user 0m0.259s
sys 0m0.496s


So it seems my kludgy bash script is almost 3x faster - that's probably the approach to optimize. Might someday redo it in c for speed, real json parsing and decent math.

As I've said I really don't know much about python so I don't know if that result might be improved. My adjust_volume.py is a very minor change from the set_volume.py included in the examples - calling cdsp.volume.adjust_fader() instead of cdsp.volume.set_main().

I could't get pyinstaller to work (it seems to think the camilladsp in site-packages isn't a package and won't load it - tried several suggested work arounds I found but no joy). Perhaps if it worked, a compiled python one-file would fair better?

I've attached the bash script here. In my flailing around for solutions I think(?) I ended up using bash shell specific feature(s) so might not run with plain sh. I'm at hack at this sort of thing so if someone has (polite) suggestions for improvement - feel free.

Cheers, Louis

[ I had to add ".txt" to the file name to get the site to upload it. Same issue with .yml files. Maybe someone has another work around? ]
 

Attachments

  • adjust_volume.sh.txt
    2 KB · Views: 16
Last edited:
Hi Henrik.

Suggestion/request for future would be to add an AdjustVolume command to the CamillaDSP web socket command set. Then my ugly script then becomes a speedy one line command like:

echo '{"AdjustVolume": value}' | websocat ws://127.0.0.1:port

Looks like websocat is available on multiple platforms.

Also, I'm wondering about the upper volume limit of +50db - seems dangerous. For my application I'd still have to script a check to keep the volume from incrementing above say, 0. With the lower limit of -150 there could be a lot of knob spinning before the signal became audible. Maybe an AdjustVolume command could include arguments for limits?

{AdjustVolume: increment : min_vol : max_vol)

Cheers, Louis
 
Last edited:
More shameless lobbying:

My application is perhaps not as fringy as it sounds. There are many usb and wireless control devices that could use this functionality. For example I'm experimenting with a newish Elgato StreamDeck+, a customizable usb control device that includes knobs as well as graphical buttons that can be configured to trigger all sorts of actions including running commands/scripts.

Cheers, Louis
 
  • Like
Reactions: 1 user
Hi Henrik,

Hmmmm....

Seems I've been working from an old CamillaDSP Web Command document ( https://henquist.github.io/0.6.3/websocket.html ). Version doesn't appear in the document, only in the URL which I didn't notice until I stumbled across the current one (https://github.com/HEnquist/camilladsp/blob/master/websocket.md) which lo and behold has an AdjustVolume command. Chalk up all that wasted scripting to "practice" :(

I also experimented with the AdjustFaderVolume but I can't seem to figure out how to format the command (more than one parameter). (fader and Increment). Since the obvious doesn't work i'm guessing it's some sort of sparse json? but I can't figure it out.

Keep getting errors similar to:

$ echo '{"AdjustFaderVolume": 0, -10}' | websocat ws://127.0.0.1:1235
{"Invalid":{"error":"invalid type: integer '0' , expected tuple variant WsCommand::AdjustFaderVolume at line 1 column 23"}}

0 being main fader and -10 being the increment.

Would you please show an example of using AdjustFaderVolume.


So it seems you already implemented part of my ask (that was fast!) but It would still be nice if the AdjustVolume and AdjustFaderVolume commands had a provision for specifying upper and lower limits.

-- Louis
 
Maybe an AdjustVolume command could include arguments for limits?
That's a good idea, I can include this in the next version.

So it seems my kludgy bash script is almost 3x faster - that's probably the approach to optimize. Might someday redo it in c for speed, real json parsing and decent math.
IIUC the knob launches a shell script on every 'click'. This is pretty inefficient, and will hurt the python script more as the python interpreter is heavier to start than bash. Is there no way to let a script (shell or python) keep running and listen for some events from the knob? That way the websocket connection can be kept alive, instead of restarting from scratch on every increment.

Perhaps if it worked, a compiled python one-file would fair better?
I don't think this matters. Those "compiled" one file executables are basically just a packaged python environment. It still needs to start up the python interpreter to run the script.

Seems I've been working from an old CamillaDSP Web Command document ( https://henquist.github.io/0.6.3/websocket.html ).
Oh that's ancient! The adjust commands have been available for quite some time.

Keep getting errors similar to:

$ echo '{"AdjustFaderVolume": 0, -10}' | websocat ws://127.0.0.1:1235
{"Invalid":{"error":"invalid type: integer '0' , expected tuple variant WsCommand::AdjustFaderVolume at line 1 column 23"}}
The command takes a single argument that should be a list of two elements. Try '{"AdjustFaderVolume": [0, -10]}'
 
The command takes a single argument that should be a list of two elements. Try '{"AdjustFaderVolume": [0, -10]}'
That worked. I'd never had figured that out. Might be something to add to the documentation (after limits on the Adjust commands :) ) . It also seems that for decimal values less that 1 the leading 0 is required. {"AdjustVolume": 0.5 } works {"AdjustVolume": .5 } gives an error. Took me a bit to figure that out. Might be something to fix or at least mention.


If the Adjust commands included limits then it does become a single command per knob increment and in my cheesy test that does around 220 steps in a second - plenty fast for good responsiveness.

bash-3.2$ time for run in {1..220}; do echo '{"AdjustFaderVolume":[ 0, 0.1]}' | websocat ws://127.0.0.1:1234 &> "/dev/null"; done
real 0m0.998s
user 0m0.314s
sys 0m0.366s


These knob things allow you to configure the increments/revolution so if one were to set it to say 40/revolution with perhaps 1 dB adjustment/increment that's a couple revolutions from full to inaudible. With the latency above, I would think it would have no problem keeping up.

Thanks, Louis
 
{"AdjustVolume": 0.5 } works {"AdjustVolume": .5 } gives an error. Took me a bit to figure that out. Might be something to fix or at least mention.
That .5 notation isn't allowed in Json, you need the zero before the decimal point.

I don't want to include a description of the Json format. But I can add a suggestion to use a validation tool such as https://jsonlint.com/
 
TNT:

Sadly, the Griffin PowerMate that I use several of is no longer available (and I think Mac specific(?)) but there are lots of this sort of device out there. It's controller software just needs to be able to fire off shell commands at some rotational interval (one for up, one for down). Then once Henrik implements the AdjustVolume (or AdjustFaderVolume) with arguments for upper and lower limits (floor and ceiling) then a command something like the ones I've been using with websocat to message the camilladsp web socket interface will be all that's needed.

Caution: The present AdjustVolume commands have a hardcoded upper limit of +50dB!!

In the mean time, If you're shell script savy and on a unix-y host (mac/linux/bsd/etc) you can try my bash script (attached earlier in the thread) which takes care of the limits (presently -100 -> 0dB). Requires websocat which is readily available. Probably need to edit some paths to suit your system.

I remain blissfully ignorant of the Windows world.

Once the new AdjustVolume & AdjustFaderVolume commands are available I'll write up something more specific.

-- Louis
 
Last edited:

TNT

Member
Joined 2003
Paid Member
I could probably succeed with now of the above. My situation is that I have a headless server (mac mini) on wifi and I would like to have the volume knob sitting on the table in front of me for an easy reach...

How do I do that?

//