plotting audio
haldean
1 year, 1 month ago
0 | 0 | [submodule "AudioFile"] |
1 | 1 | path = AudioFile |
2 | 2 | url = https://github.com/adamstark/AudioFile |
3 | [submodule "implot"] | |
4 | path = implot | |
5 | url = https://github.com/epezent/implot |
24 | 24 | cimgui/imgui/imgui_widgets.cpp |
25 | 25 | cimgui/imgui/imgui_draw.cpp |
26 | 26 | cimgui/imgui/imgui_tables.cpp |
27 | cimgui/imgui/imgui_demo.cpp) | |
27 | cimgui/imgui/imgui_demo.cpp | |
28 | implot/implot.h | |
29 | implot/implot_internal.h | |
30 | implot/implot.cpp | |
31 | implot/implot_items.cpp | |
32 | implot/implot_demo.cpp) | |
28 | 33 | target_include_directories(cimgui INTERFACE cimgui) |
34 | target_include_directories(cimgui PRIVATE cimgui/imgui) | |
29 | 35 | |
30 | 36 | #=== LIBRARY: sokol |
31 | 37 | # add headers to the the file list because they are useful to have in IDEs |
70 | 76 | else() |
71 | 77 | add_executable(qb ${QB_SOURCES}) |
72 | 78 | endif() |
79 | target_include_directories(qb PRIVATE cimgui/imgui implot) | |
73 | 80 | target_link_libraries(qb sokol) |
74 | 81 | |
75 | 82 | # explicitly strip dead code |
0 | cmake_minimum_required(VERSION 3.0) | |
1 | project(cimgui-sokol-starterkit) | |
2 | set(CMAKE_C_STANDARD 11) | |
3 | set(CMAKE_CXX_STANDARD 17) | |
4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
5 | if (CMAKE_SYSTEM_NAME STREQUAL Emscripten) | |
6 | set(CMAKE_EXECUTABLE_SUFFIX ".html") | |
7 | endif() | |
8 | if(MSVC) | |
9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") | |
10 | endif(MSVC) | |
11 | ||
12 | # Linux -pthread shenanigans | |
13 | if (CMAKE_SYSTEM_NAME STREQUAL Linux) | |
14 | set(THREADS_PREFER_PTHREAD_FLAG ON) | |
15 | find_package(Threads REQUIRED) | |
16 | endif() | |
17 | ||
18 | #=== LIBRARY: cimgui + Dear ImGui | |
19 | add_library(cimgui STATIC | |
20 | cimgui/cimgui.cpp | |
21 | cimgui/cimgui.h | |
22 | cimgui/imgui/imgui.cpp | |
23 | cimgui/imgui/imgui.h | |
24 | cimgui/imgui/imgui_widgets.cpp | |
25 | cimgui/imgui/imgui_draw.cpp | |
26 | cimgui/imgui/imgui_tables.cpp | |
27 | cimgui/imgui/imgui_demo.cpp | |
28 | implot/implot.h | |
29 | implot/implot_internal.h | |
30 | implot/implot.cpp | |
31 | implot/implot_items.cpp | |
32 | implot/implot_demo.cpp) | |
33 | target_include_directories(cimgui INTERFACE cimgui) | |
34 | target_include_directories(cimgui PRIVATE cimgui/imgui) | |
35 | ||
36 | #=== LIBRARY: sokol | |
37 | # add headers to the the file list because they are useful to have in IDEs | |
38 | set(SOKOL_HEADERS | |
39 | sokol/sokol_gfx.h | |
40 | sokol/sokol_app.h | |
41 | sokol/sokol_time.h | |
42 | sokol/sokol_imgui.h | |
43 | sokol/sokol_glue.h) | |
44 | if(CMAKE_SYSTEM_NAME STREQUAL Darwin) | |
45 | add_library(sokol STATIC sokol/sokol.m ${SOKOL_HEADERS}) | |
46 | target_link_libraries(sokol PUBLIC | |
47 | "-framework QuartzCore" | |
48 | "-framework Cocoa" | |
49 | "-framework MetalKit" | |
50 | "-framework Metal") | |
51 | else() | |
52 | add_library(sokol STATIC sokol/sokol.c ${SOKOL_HEADERS}) | |
53 | if (CMAKE_SYSTEM_NAME STREQUAL Linux) | |
54 | target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL dl m) | |
55 | target_link_libraries(sokol PUBLIC Threads::Threads) | |
56 | endif() | |
57 | endif() | |
58 | target_link_libraries(sokol PUBLIC cimgui) | |
59 | target_include_directories(sokol INTERFACE sokol) | |
60 | ||
61 | #=== EXECUTABLE: qb | |
62 | set(QB_SOURCES | |
63 | launch.c | |
64 | qb.cpp | |
65 | qb.hpp | |
66 | qbshim.cpp | |
67 | qbshim.hpp | |
68 | nodeui.cpp | |
69 | nodeui.hpp | |
70 | task.cpp | |
71 | task.hpp | |
72 | AudioFile/AudioFile.h | |
73 | ) | |
74 | if(CMAKE_SYSTEM_NAME STREQUAL Windows) | |
75 | add_executable(qb WIN32 ${QB_SOURCES}) | |
76 | else() | |
77 | add_executable(qb ${QB_SOURCES}) | |
78 | endif() | |
79 | target_include_directories(qb PRIVATE cimgui/imgui implot) | |
80 | target_link_libraries(qb sokol) | |
81 | ||
82 | # explicitly strip dead code | |
83 | if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten) | |
84 | target_link_options(qb PRIVATE LINKER:-dead_strip) | |
85 | endif() | |
86 | ||
87 | # this hack removes the xxx-CMakeForceLinker.cxx dummy file | |
88 | set_target_properties(qb PROPERTIES LINKER_LANGUAGE C) |
1 | 1 | #include "nodeui.hpp" |
2 | 2 | |
3 | 3 | #include "AudioFile/AudioFile.h" |
4 | #include "cimgui/imgui/imgui.h" | |
4 | #include "imgui.h" | |
5 | #include "implot.h" | |
5 | 6 | |
6 | 7 | namespace qb { |
7 | 8 | |
40 | 41 | ImGui::DragInt("off", &off, 1.0, 0, INT_MAX); |
41 | 42 | |
42 | 43 | const std::vector<float> &r = node->rendered(); |
44 | /* | |
43 | 45 | ImGui::PlotLines("samples", r.data(), |
44 | 46 | std::min((int)r.size() - off, len), |
45 | 47 | std::min((int)r.size() - 1, off)); |
48 | */ | |
49 | ||
50 | //ImPlot::SetNextPlotLimitsY(-1.0, 1.0, ImGuiCond_Always); | |
51 | if (ImPlot::BeginPlot("samples", "frame", "amp", ImVec2(-1, 0), | |
52 | ImPlotFlags_NoTitle | ImPlotFlags_NoLegend, | |
53 | ImPlotAxisFlags_AutoFit)) { | |
54 | ImPlot::PlotLine("mono", r.data(), r.size()); | |
55 | ImPlot::EndPlot(); | |
56 | } | |
46 | 57 | } |
47 | 58 | } |
48 | 59 | } |
6 | 6 | |
7 | 7 | namespace qb { |
8 | 8 | context::context() { |
9 | _nodes.push_back(std::make_shared<qb::audio_node>(this, "test/coc-stereo.wav")); | |
9 | _nodes.push_back(std::make_shared<qb::audio_node>(this, "test/coc-mono.wav")); | |
10 | 10 | } |
11 | 11 | |
12 | 12 | void context::frame(int width, int height) { |
0 | 0 | #include "qb.hpp" |
1 | 1 | #include "qbshim.hpp" |
2 | ||
3 | #include "implot/implot.h" | |
2 | 4 | |
3 | 5 | qb_context_ptr |
4 | 6 | qb_init() |
5 | 7 | { |
8 | ImPlot::CreateContext(); | |
6 | 9 | return new qb::context(); |
7 | 10 | } |
8 | 11 | |
13 | 16 | |
14 | 17 | void qb_shutdown(qb_context_ptr ctx) |
15 | 18 | { |
19 | ImPlot::DestroyContext(); | |
16 | 20 | reinterpret_cast<qb::context*>(ctx)->shutdown(); |
17 | 21 | } |