git.haldean.org ana / 950c621
load audio files haldean 8 months ago
7 changed file(s) with 76 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11 src/ana.cpp \
22 src/font.gen.cpp \
33 src/node.cpp \
4 src/nodeui.cpp \
45 src/reallocarray.cpp \
56 src/ui.cpp \
67 src/viewport.cpp \
2223 CXXFLAGS += -I lib/glew-2.1.0/include
2324 CXXFLAGS += -I lib/glfw-3.2.1.bin.WIN64/include
2425 CXXFLAGS += -I lib/glm
26 CXXFLAGS += -I lib/AudioFile
2527 CXXFLAGS += -MD
2628 CXXFLAGS += -ggdb
2729
1111
1212 #include "model.hpp"
1313 #include "node.hpp"
14 #include "nodeui.hpp"
1415 #include "ui.hpp"
1516 #include "viewport.hpp"
1617
104105 ImGuiWindowFlags_NoDecoration);
105106
106107 for (const ana::node_ptr &n : model.nodes) {
107 ImGui::Text(n->name().c_str());
108 ana::nodeui::draw(n);
108109 }
109110
110111 ImGui::End();
0 namespace ana {
1 struct audio_file {
2
3 };
4 }
00 #include "node.hpp"
1 #include "AudioFile.h"
12
23 namespace ana {
34
45 node::node(const std::string &n, node_type t) : _name(n), _type(t) {}
56
7
8 class audio_file : public AudioFile<float> {
9 using AudioFile::AudioFile;
10 };
11
612 audio_node::audio_node(const fs::path &path)
713 : node(path.filename(), ana::node_type::audio)
814 , _path(path)
915 {
16 _data.reset(new audio_file());
17 _loaded = _data->load(path.string());
1018 }
1119
20 audio_node::~audio_node() = default;
21
1222 }
3737 };
3838 using node_ptr = std::shared_ptr<node>;
3939
40 class audio_file;
4041 struct audio_node : public node {
4142 explicit audio_node(const fs::path &path);
42 ~audio_node() override = default;
43 ~audio_node() override;
4344
4445 const fs::path &path() const {
4546 return _path;
4647 }
4748
49 bool loaded() const {
50 return _loaded;
51 }
52
4853 private:
4954 const fs::path _path;
55 std::unique_ptr<audio_file> _data;
56 bool _loaded;
5057 };
5158
5259 }
0 #include "nodeui.hpp"
1
2 #include "imgui.h"
3
4 namespace ana {
5 namespace nodeui {
6
7 void draw(const std::shared_ptr<ana::audio_node> &node)
8 {
9 if (not node->loaded()) {
10 ImGui::Text("failed to load file %s", node->path().c_str());
11 return;
12 }
13 ImGui::Text(node->path().c_str());
14 }
15
16 template <class To, class From>
17 std::shared_ptr<To> checked_cast(const std::shared_ptr<From> &p) {
18 const auto res = std::dynamic_pointer_cast<To>(p);
19 if (not res) {
20 throw ("bad cast to " + std::string(typeid(To).name()));
21 }
22 return res;
23 }
24
25 void draw(const ana::node_ptr &node)
26 {
27 switch (node->type()) {
28 case ana::node_type::audio:
29 draw(checked_cast<ana::audio_node>(node));
30 return;
31 case ana::node_type::midi:
32 ImGui::Text("no drawing for midi nodes yet");
33 break;
34 case ana::node_type::osc:
35 ImGui::Text("no drawing for osc nodes yet");
36 break;
37 }
38 }
39
40 } // nodeui
41 } // ana
0 #include "node.hpp"
1
2 namespace ana {
3 namespace nodeui {
4 void draw(const ana::node_ptr &node);
5 }
6 }