git.haldean.org ana / d8e3a72
start working on audio node support haldean 8 months ago
7 changed file(s) with 145 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
33 [submodule "lib/imgui"]
44 path = lib/imgui
55 url = https://github.com/ocornut/imgui
6 [submodule "lib/AudioFile"]
7 path = lib/AudioFile
8 url = https://github.com/adamstark/AudioFile
22 src/font.gen.cpp \
33 src/node.cpp \
44 src/reallocarray.cpp \
5 src/shaders.cpp \
65 src/ui.cpp \
76 src/viewport.cpp \
87 lib/imgui/imgui.cpp \
1514 objects = $(patsubst %.cpp,%.o,$(cxx_sources))
1615 deps = $(patsubst %.cpp,%.d,$(cxx_sources))
1716
17 CXXFLAGS += -std=c++17
1818 CXXFLAGS += -DIMGUI_IMPL_OPENGL_LOADER_GLEW
1919 CXXFLAGS += -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS
2020 CXXFLAGS += -I lib/imgui
0 cxx_sources = \
1 src/ana.cpp \
2 src/font.gen.cpp \
3 src/node.cpp \
4 src/reallocarray.cpp \
5 src/ui.cpp \
6 src/viewport.cpp \
7 lib/imgui/imgui.cpp \
8 lib/imgui/imgui_demo.cpp \
9 lib/imgui/imgui_draw.cpp \
10 lib/imgui/imgui_widgets.cpp \
11 lib/imgui/examples/imgui_impl_opengl3.cpp \
12 lib/imgui/examples/imgui_impl_glfw.cpp
13
14 objects = $(patsubst %.cpp,%.o,$(cxx_sources))
15 deps = $(patsubst %.cpp,%.d,$(cxx_sources))
16
17 CXXFLAGS += -std=c++17
18 CXXFLAGS += -DIMGUI_IMPL_OPENGL_LOADER_GLEW
19 CXXFLAGS += -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS
20 CXXFLAGS += -I lib/imgui
21 CXXFLAGS += -I lib/imgui/examples
22 CXXFLAGS += -I lib/glew-2.1.0/include
23 CXXFLAGS += -I lib/glfw-3.2.1.bin.WIN64/include
24 CXXFLAGS += -I lib/glm
25 CXXFLAGS += -MD
26 CXXFLAGS += -ggdb
27
28 ifdef OS
29 # Windows
30 LDFLAGS += lib\glew-2.1.0\lib\Release\x64\glew32.lib
31 LDFLAGS += lib\glfw-3.2.1.bin.WIN64\lib-mingw-w64\libglfw3.a
32 LDFLAGS += -lopengl32
33 LDFLAGS += -lgdi32
34 LDFLAGS += -lglu32
35 LDFLAGS += -lshell32
36 LDFLAGS += -ggdb
37
38 build/glew32.dll: lib/glew-2.1.0/bin/Release/x64/glew32.dll build
39 cp $< $@
40
41 dist: build/ana.exe build/glew32.dll
42
43 else
44 # Not-windows
45 LDFLAGS += -lglfw
46 LDFLAGS += -lGLEW
47 LDFLAGS += -lGL
48
49 dist: build/ana.exe
50 endif
51
52 build:
53 mkdir build
54
55 build/ana.exe: $(objects) build
56 $(CXX) $(objects) $(LDFLAGS) -o $@
57
58 XD = tool/xd.exe
59
60 $(XD): tool/xd-1.4/xd.o
61 $(CXX) $< -o $@
62
63 src/font.gen.cpp: data/InputMonoNarrow-Regular.ttf $(XD)
64 $(XD) -dfont_data $< $@
65
66 -include $(patsubst %.o,%.d,$(objects))
67
68 clean:
69 rm -rf $(objects) $(deps) build tool/xd-1.4/xd.o tool/xd.exe
70 .PHONY: clean
00
11 #include <cstdlib>
2 #include <filesystem>
23 #include <iostream>
34
45 #include <GL/glew.h>
89 #include "imgui_impl_opengl3.h"
910 #include "imgui_impl_glfw.h"
1011
12 #include "model.hpp"
1113 #include "node.hpp"
12 #include "shaders.hpp"
1314 #include "ui.hpp"
1415 #include "viewport.hpp"
16
17 namespace fs = std::filesystem;
1518
1619 static ana::viewport viewport;
1720
7073 glfwSetScrollCallback(window, scroll_callback);
7174 glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
7275
73 if (!ana::shaders::init())
74 return EXIT_FAILURE;
75
7676 glEnable(GL_BLEND);
7777 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
7878
79 ana::nodeset nodes;
80 nodes.nodes.push_back(ana::node("track one"));
81 nodes.nodes.push_back(ana::node("track two"));
82 nodes.nodes.push_back(ana::node("track three"));
83 nodes.nodes.push_back(ana::node("track four"));
84 nodes.nodes.push_back(ana::node("track five"));
85 nodes.nodes.push_back(ana::node("track six"));
86 nodes.nodes.push_back(ana::node("track seven"));
87 nodes.nodes.push_back(ana::node("track eight"));
88 nodes.nodes.push_back(ana::node("track nine"));
89 nodes.nodes.push_back(ana::node("track ten"));
79 ana::model model;
80 model.add<ana::audio_node>(fs::path("test/track1.wav"));
9081
9182 ImGui::CreateContext();
9283 ana::ui::init_imgui();
112103 ImGuiWindowFlags_NoResize |
113104 ImGuiWindowFlags_NoDecoration);
114105
115 for (const ana::node &n : nodes.nodes) {
116 ImGui::Text(n.name.c_str());
106 for (const ana::node_ptr &n : model.nodes) {
107 ImGui::Text(n->name().c_str());
117108 }
118109
119110 ImGui::End();
121112 ImGui::Render();
122113
123114 glClear(GL_COLOR_BUFFER_BIT);
124 ana::shaders::draw(viewport, nodes);
125115 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
126116 glfwMakeContextCurrent(window);
127117 glfwSwapBuffers(window);
128118 }
129119
130 ana::shaders::destroy();
131120 ImGui_ImplOpenGL3_Shutdown();
132121 ImGui_ImplGlfw_Shutdown();
133122 glfwTerminate();
0 #include <vector>
1
2 #include "node.hpp"
3
4 namespace ana {
5
6 struct model {
7 std::vector<ana::node_ptr> nodes;
8
9 template <class T, class... Args>
10 void add(Args&&... args) {
11 nodes.push_back(std::make_shared<T>(std::forward<Args>(args)...));
12 }
13 };
14
15 }
11
22 namespace ana {
33
4 node::node(std::string n) : name(n) {}
4 node::node(const std::string &n, node_type t) : _name(n), _type(t) {}
55
6 size_t nodeset::size() const {
7 return nodes.size();
6 audio_node::audio_node(const fs::path &path)
7 : node(path.filename(), ana::node_type::audio)
8 , _path(path)
9 {
810 }
911
1012 }
00 #pragma once
1 #include <glm/vec2.hpp>
1 #include <filesystem>
2 #include <memory>
23 #include <string>
34 #include <vector>
45
56 namespace ana {
67
7 struct node {
8 std::string name;
8 namespace fs = std::filesystem;
99
10 explicit node(std::string n);
11 node(const node&) = default;
10 enum class node_type {
11 audio,
12 midi,
13 osc,
1214 };
1315
14 struct nodeset {
15 size_t size() const;
16 std::vector<node> nodes;
16 struct node {
17 node(const node&) = delete;
18 node(node&&) = delete;
19 node &operator=(const node&) = delete;
20 node &operator=(node&&) = delete;
21
22 virtual ~node() = default;
23
24 const std::string &name() const {
25 return _name;
26 }
27 node_type type() const {
28 return _type;
29 }
30
31 protected:
32 node(const std::string &n, node_type t);
33
34 private:
35 std::string _name;
36 node_type _type;
37 };
38 using node_ptr = std::shared_ptr<node>;
39
40 struct audio_node : public node {
41 explicit audio_node(const fs::path &path);
42 ~audio_node() override = default;
43
44 const fs::path &path() const {
45 return _path;
46 }
47
48 private:
49 const fs::path _path;
1750 };
1851
1952 }