From ba0eebbb4a02c2c6bc4b2e0b55f1ee56e2073a31 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 6 Nov 2023 13:36:54 -0500 Subject: Cleanup cmv Signed-off-by: Andrew Opalach --- .gitignore | 1 - flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 4 +++- src/fruits/cmv/cmv2.c | 22 +++++++++++-------- src/libsink/sink.c | 2 +- src/screen/screen.h | 4 ++-- 6 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 flake.lock diff --git a/.gitignore b/.gitignore index 79b95a9..5499539 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ build*/ compile_commands.json .cache/ .clangd/ -flake.lock bin/ data/ doc/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7bdd046 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1699099776, + "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 7ed5944..8c5c704 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,7 @@ { devShells.default = mkShell { nativeBuildInputs = [ + zsh gcc gdb perf-tools @@ -52,12 +53,13 @@ nlohmann_json ]; shellHook = '' + export NIX_SHELL=true # https://nixos.wiki/wiki/Python#Emulating_virtualenv_with_nix-shell export PIP_PREFIX=$(pwd)/vshell/pip_packages export PYTHONPATH="$PIP_PREFIX/${pkgs.python3.sitePackages}:$PYTHONPATH" export PATH="$PIP_PREFIX/bin:$PATH" unset SOURCE_DATE_EPOCH - export PS1="\e[33m(camu):\w >\e(B\e[m " + exec ${pkgs.zsh}/bin/zsh ''; }; } diff --git a/src/fruits/cmv/cmv2.c b/src/fruits/cmv/cmv2.c index a7b688c..963cf7a 100644 --- a/src/fruits/cmv/cmv2.c +++ b/src/fruits/cmv/cmv2.c @@ -1,4 +1,5 @@ #define CMV_USE_TUI 1 +#define CMV_USE_SOCKET 1 #include #include @@ -28,9 +29,11 @@ struct cmv { struct camu_mixer mixer; struct aki_event_loop loop; struct camu_sink sink; + struct cap_runner cap; +#if CMV_USE_SOCKET struct aki_socket socket; struct aki_line_processor pro; - struct cap_runner cap; +#endif #if CMV_USE_TUI struct cmv_tui tui; struct aki_timer timer; @@ -38,6 +41,7 @@ struct cmv { }; static struct cmv c; + static str *default_list = al_str_c("default"); static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque) @@ -121,8 +125,11 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque) } break; case CAMU_SINK_EXIT: - aki_event_loop_break(&c->loop); +#if CMV_USE_SOCKET + aki_line_processor_stop(&c->pro); +#endif camu_sink_close(&c->sink); + aki_event_loop_break(&c->loop); break; } return CAMU_SINK_OK; @@ -132,9 +139,6 @@ static void screen_callback(void *userdata, u8 op, f64 float0) { struct cmv *c = (struct cmv *)userdata; switch (op) { - case CAMU_SCREEN_CLOSE: - c->quit = 1; - break; case CAMU_SCREEN_NEXT: cap_list_skip(&c->cap, default_list, 1); break; @@ -147,7 +151,8 @@ static void screen_callback(void *userdata, u8 op, f64 float0) case CAMU_SCREEN_SEEK: camu_sink_seek(&c->sink, float0); break; - default: + case CAMU_SCREEN_CLOSE: + c->quit = 1; break; } } @@ -180,7 +185,7 @@ static bool cap_callback(void *userdata, u8 op, str *name, str *unique_id, void return true; } -#ifndef _WIN32 +#if CMV_USE_SOCKET static u8 line_callback(void *userdata, str *line) { struct cmv *c = (struct cmv *)userdata; @@ -274,11 +279,10 @@ s32 main(s32 argc, char *argv[]) cap_list_add(&c.cap, default_list, al_str_c(argv[i])); } -#ifndef _WIN32 +#if CMV_USE_SOCKET c.socket.type = AKI_SOCKET_UNIX; aki_socket_init(&c.socket); aki_socket_set_blocking(&c.socket, false); - aki_socket_set_no_delay(&c.socket, 1); c.pro.callback = line_callback; c.pro.userdata = &c; aki_line_processor_init(&c.pro, al_str_c("\n")); diff --git a/src/libsink/sink.c b/src/libsink/sink.c index cf8328a..5ca9106 100644 --- a/src/libsink/sink.c +++ b/src/libsink/sink.c @@ -149,7 +149,7 @@ static void handle_sink_cmd(struct camu_sink *sink, struct camu_sink_cmd *cmd) } case CLOSE: { sink->callback(sink->userdata, CAMU_SINK_EXIT, 0, NULL); - break; + return; } } } diff --git a/src/screen/screen.h b/src/screen/screen.h index d45d5ee..798fc8e 100644 --- a/src/screen/screen.h +++ b/src/screen/screen.h @@ -31,9 +31,9 @@ enum { }; enum { - CAMU_SCREEN_TOGGLE_PAUSE = 0, - CAMU_SCREEN_NEXT, + CAMU_SCREEN_NEXT = 0, CAMU_SCREEN_PREVIOUS, + CAMU_SCREEN_TOGGLE_PAUSE, CAMU_SCREEN_SEEK, CAMU_SCREEN_CLOSE }; -- cgit v1.2.3-101-g0448