git.haldean.org qb / 5c28368
plotting audio haldean 1 year, 1 month ago
6 changed file(s) with 117 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 [submodule "AudioFile"]
11 path = AudioFile
22 url = https://github.com/adamstark/AudioFile
3 [submodule "implot"]
4 path = implot
5 url = https://github.com/epezent/implot
2424 cimgui/imgui/imgui_widgets.cpp
2525 cimgui/imgui/imgui_draw.cpp
2626 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)
2833 target_include_directories(cimgui INTERFACE cimgui)
34 target_include_directories(cimgui PRIVATE cimgui/imgui)
2935
3036 #=== LIBRARY: sokol
3137 # add headers to the the file list because they are useful to have in IDEs
7076 else()
7177 add_executable(qb ${QB_SOURCES})
7278 endif()
79 target_include_directories(qb PRIVATE cimgui/imgui implot)
7380 target_link_libraries(qb sokol)
7481
7582 # 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)
11 #include "nodeui.hpp"
22
33 #include "AudioFile/AudioFile.h"
4 #include "cimgui/imgui/imgui.h"
4 #include "imgui.h"
5 #include "implot.h"
56
67 namespace qb {
78
4041 ImGui::DragInt("off", &off, 1.0, 0, INT_MAX);
4142
4243 const std::vector<float> &r = node->rendered();
44 /*
4345 ImGui::PlotLines("samples", r.data(),
4446 std::min((int)r.size() - off, len),
4547 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 }
4657 }
4758 }
4859 }
66
77 namespace qb {
88 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"));
1010 }
1111
1212 void context::frame(int width, int height) {
00 #include "qb.hpp"
11 #include "qbshim.hpp"
2
3 #include "implot/implot.h"
24
35 qb_context_ptr
46 qb_init()
57 {
8 ImPlot::CreateContext();
69 return new qb::context();
710 }
811
1316
1417 void qb_shutdown(qb_context_ptr ctx)
1518 {
19 ImPlot::DestroyContext();
1620 reinterpret_cast<qb::context*>(ctx)->shutdown();
1721 }