Code Monkey home page Code Monkey logo

smhkd's Introduction

smhkd License

smhkd (Simple MIDI hotkontrol daemon) is a daemon that reacts to MIDI events by executing commands.

It's inspired by sxhkd, but handles ALSA MIDI events rather than X events.

Current Status

smhkd is still in design phase and not yet ready for mainstream usage.

At the moment, and at the moment only, it reads a configuration file in ~/.config/smhkd/smhkdrc.json, which looks like this:

{
    "@nanoKONTROL2": {
        "0": "pactl set-sink-volume @DEFAULT_SINK@ $VALUE%",
        "32": "pactl set-sink-volume @DEFAULT_SINK@ 100%",
        "48": "pactl set-sink-volume @DEFAULT_SINK@ 30%",
        "64": "pactl set-sink-volume @DEFAULT_SINK@ 0%",
        "7": "v4l2-ctl -d /dev/video0 --set-ctrl=zoom_absolute=$VALUE"
    },
    "129:0": {
        "1": "pactl set-sink-volume @DEFAULT_SINK@ $VALUE%",
        "67": "pactl set-sink-volume @DEFAULT_SINK@ 100%",
        "66": "pactl set-sink-volume @DEFAULT_SINK@ 30%",
        "64": "pactl set-sink-volume @DEFAULT_SINK@ 0%"
    }
}

and it listens to each pair of client and port (28:0 — where 28 is the client number for nanoKONTROL2 and 0 the first available port for it — 129:0 and so on…) for MIDI events.

Every time it receives an event, it runs the command associated with the controller ID (if any). Occurences of $VALUE in that command are replaced with the value of the event. In the example above, it sets the volume of a PulseAudio sink (which can actually be a PipeWire) or the zoom level of a webcam, but any command could be executed instead.

Keep in mind that this configuration format is only temporary and will ultimately be replaced with something more similar to what sxhkd uses. There is no plan to provide backward compatibility with JSON or even a migration path when than happens.

Usage

Usage: smhkd list
       smhkd run
       smhkd -h | --help
       smhkd --version

Commands:
    list                     List available MIDI controllers.
    run                      Listen to MIDI events and run commands.

Arguments:

Options:
    -h, --help               Show this screen.
    --version                Show version.

Running on startup

Run systemctl --user enable --now smhkd after installing.

Compiling

Run cargo build --release in your working copy.

Contributing and reporting bugs

Contributions are welcome through GitHub pull requests.

Please report bugs and feature requests on GitHub issues.

License

smhkd is copyright (C) 2022-2024 Jérémie Roquet [email protected] and licensed under the ISC license.

smhkd's People

Contributors

arkanosis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

smhkd's Issues

panick when running shell command

Just toying with the tool (not serious use).

Simple shell function in my path:

bladie() {
    echo $1 >> /home/dreamer/something.txt;
}

And my config:

{
    "44:0": {
        "1": "bladie $VALUE"
    }
}

Results in:

dreamer@auditorium:~/Sources/_audio/smhkd$ RUST_BACKTRACE=full ./target/release/smhkd run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/lib.rs:155:30
stack backtrace:
   0:     0x55ea5fb81a50 - std::backtrace_rs::backtrace::libunwind::trace::h7caa80dd3371e2c2
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x55ea5fb81a50 - std::backtrace_rs::backtrace::trace_unsynchronized::h00c00446f474689e
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55ea5fb81a50 - std::sys_common::backtrace::_print_fmt::h640bf43236c0599a
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x55ea5fb81a50 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h00ba5fc51424fda0
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x55ea5fba004e - core::fmt::write::h79a050f3cd290e78
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/core/src/fmt/mod.rs:1202:17
   5:     0x55ea5fb7f1c5 - std::io::Write::write_fmt::h6021ee0a724eb6a6
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/io/mod.rs:1679:15
   6:     0x55ea5fb830d3 - std::sys_common::backtrace::_print::hbaf566e4bb76b06a
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x55ea5fb830d3 - std::sys_common::backtrace::print::h9699d33e77a11b30
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x55ea5fb830d3 - std::panicking::default_hook::{{closure}}::h1448de4b6432b818
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:295:22
   9:     0x55ea5fb82dbf - std::panicking::default_hook::hb22165178ea6ebe1
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:314:9
  10:     0x55ea5fb8377a - std::panicking::rust_panic_with_hook::h9ff5d983a027100b
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:698:17
  11:     0x55ea5fb83677 - std::panicking::begin_panic_handler::{{closure}}::he13c1e1bcef23171
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:588:13
  12:     0x55ea5fb81efc - std::sys_common::backtrace::__rust_end_short_backtrace::hb7039cc0b9081287
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x55ea5fb83392 - rust_begin_unwind
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:584:5
  14:     0x55ea5fab16b3 - core::panicking::panic_fmt::hce4e59acd88a04ff
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/core/src/panicking.rs:142:14
  15:     0x55ea5fab17a3 - core::result::unwrap_failed::h20b7c16f09880811
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/core/src/result.rs:1785:5
  16:     0x55ea5fab70c0 - smhkd::run::h92157e73cbd77a07
  17:     0x55ea5fab4183 - smhkd::main::h4a435f8bcbd614c1
  18:     0x55ea5fab2173 - std::sys_common::backtrace::__rust_begin_short_backtrace::he3b3d3572d44c2e8
  19:     0x55ea5fab2189 - std::rt::lang_start::{{closure}}::h0ef193ceceea301b
  20:     0x55ea5fb7be9f - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h2f24867226efc564
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/core/src/ops/function.rs:280:13
  21:     0x55ea5fb7be9f - std::panicking::try::do_call::hf081aab314c798aa
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:492:40
  22:     0x55ea5fb7be9f - std::panicking::try::h8a4865661cfc585a
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:456:19
  23:     0x55ea5fb7be9f - std::panic::catch_unwind::h26256cf7a601360a
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panic.rs:137:14
  24:     0x55ea5fb7be9f - std::rt::lang_start_internal::{{closure}}::h86ab66fc87a49421
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/rt.rs:148:48
  25:     0x55ea5fb7be9f - std::panicking::try::do_call::h95309420b1953195
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:492:40
  26:     0x55ea5fb7be9f - std::panicking::try::h37122e4d07c522e8
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panicking.rs:456:19
  27:     0x55ea5fb7be9f - std::panic::catch_unwind::h96e1dfea4e6763ec
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/panic.rs:137:14
  28:     0x55ea5fb7be9f - std::rt::lang_start_internal::h51e5752448dfe66f
                               at /rustc/fa6ee9375242ae784dab1837dfc0b92f43e787ce/library/std/src/rt.rs:148:20
  29:     0x55ea5fab42e8 - main
  30:     0x7f20c842f1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  31:     0x7f20c842f285 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  32:     0x55ea5fab18e1 - _start
  33:                0x0 - <unknown>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.