start working on audio node support
haldean
1 year, 10 months ago
3 | 3 | [submodule "lib/imgui"] |
4 | 4 | path = lib/imgui |
5 | 5 | url = https://github.com/ocornut/imgui |
6 | [submodule "lib/AudioFile"] | |
7 | path = lib/AudioFile | |
8 | url = https://github.com/adamstark/AudioFile |
2 | 2 | src/font.gen.cpp \ |
3 | 3 | src/node.cpp \ |
4 | 4 | src/reallocarray.cpp \ |
5 | src/shaders.cpp \ | |
6 | 5 | src/ui.cpp \ |
7 | 6 | src/viewport.cpp \ |
8 | 7 | lib/imgui/imgui.cpp \ |
15 | 14 | objects = $(patsubst %.cpp,%.o,$(cxx_sources)) |
16 | 15 | deps = $(patsubst %.cpp,%.d,$(cxx_sources)) |
17 | 16 | |
17 | CXXFLAGS += -std=c++17 | |
18 | 18 | CXXFLAGS += -DIMGUI_IMPL_OPENGL_LOADER_GLEW |
19 | 19 | CXXFLAGS += -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS |
20 | 20 | 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 |
0 | 0 | |
1 | 1 | #include <cstdlib> |
2 | #include <filesystem> | |
2 | 3 | #include <iostream> |
3 | 4 | |
4 | 5 | #include <GL/glew.h> |
8 | 9 | #include "imgui_impl_opengl3.h" |
9 | 10 | #include "imgui_impl_glfw.h" |
10 | 11 | |
12 | #include "model.hpp" | |
11 | 13 | #include "node.hpp" |
12 | #include "shaders.hpp" | |
13 | 14 | #include "ui.hpp" |
14 | 15 | #include "viewport.hpp" |
16 | ||
17 | namespace fs = std::filesystem; | |
15 | 18 | |
16 | 19 | static ana::viewport viewport; |
17 | 20 | |
70 | 73 | glfwSetScrollCallback(window, scroll_callback); |
71 | 74 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); |
72 | 75 | |
73 | if (!ana::shaders::init()) | |
74 | return EXIT_FAILURE; | |
75 | ||
76 | 76 | glEnable(GL_BLEND); |
77 | 77 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
78 | 78 | |
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")); | |
90 | 81 | |
91 | 82 | ImGui::CreateContext(); |
92 | 83 | ana::ui::init_imgui(); |
112 | 103 | ImGuiWindowFlags_NoResize | |
113 | 104 | ImGuiWindowFlags_NoDecoration); |
114 | 105 | |
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()); | |
117 | 108 | } |
118 | 109 | |
119 | 110 | ImGui::End(); |
121 | 112 | ImGui::Render(); |
122 | 113 | |
123 | 114 | glClear(GL_COLOR_BUFFER_BIT); |
124 | ana::shaders::draw(viewport, nodes); | |
125 | 115 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
126 | 116 | glfwMakeContextCurrent(window); |
127 | 117 | glfwSwapBuffers(window); |
128 | 118 | } |
129 | 119 | |
130 | ana::shaders::destroy(); | |
131 | 120 | ImGui_ImplOpenGL3_Shutdown(); |
132 | 121 | ImGui_ImplGlfw_Shutdown(); |
133 | 122 | 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 | } |
1 | 1 | |
2 | 2 | namespace ana { |
3 | 3 | |
4 | node::node(std::string n) : name(n) {} | |
4 | node::node(const std::string &n, node_type t) : _name(n), _type(t) {} | |
5 | 5 | |
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 | { | |
8 | 10 | } |
9 | 11 | |
10 | 12 | } |
0 | 0 | #pragma once |
1 | #include <glm/vec2.hpp> | |
1 | #include <filesystem> | |
2 | #include <memory> | |
2 | 3 | #include <string> |
3 | 4 | #include <vector> |
4 | 5 | |
5 | 6 | namespace ana { |
6 | 7 | |
7 | struct node { | |
8 | std::string name; | |
8 | namespace fs = std::filesystem; | |
9 | 9 | |
10 | explicit node(std::string n); | |
11 | node(const node&) = default; | |
10 | enum class node_type { | |
11 | audio, | |
12 | midi, | |
13 | osc, | |
12 | 14 | }; |
13 | 15 | |
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; | |
17 | 50 | }; |
18 | 51 | |
19 | 52 | } |