git.haldean.org qb / cd552ee
more moving stuff around, no more warnings on msvc haldean 5 months ago
6 changed file(s) with 69 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
6464 set(QB_SOURCES
6565 launch.c
6666 audionode.cpp
67 audionode.hpp
6768 colors.cpp
6869 colors.hpp
6970 qb.cpp
7677 task.hpp
7778 AudioFile/AudioFile.h
7879 )
80 if (MSVC)
81 add_compile_options(/EHsc)
82 endif()
7983 if(CMAKE_SYSTEM_NAME STREQUAL Windows)
8084 add_executable(qb WIN32 ${QB_SOURCES})
8185 else()
00 #include "qb.hpp"
1 #include "audionode.hpp"
12 #include "task.hpp"
3
24 #include "AudioFile/AudioFile.h"
35 #include "AudioFFT/AudioFFT.h"
46
0 #ifndef audionode_hpp
1 #define audionode_hpp
2
3 #include <vector>
4
5 #include "qb.hpp"
6
7 #include "AudioFile/AudioFile.h"
8
9 namespace qb {
10 using audio_file = AudioFile<float>;
11 using audio_file_ptr = std::shared_ptr<audio_file>;
12 using audio_file_cptr = std::shared_ptr<const audio_file>;
13
14 struct audio_node : public node {
15 audio_node(const context *c, const std::string &path);
16 ~audio_node() override;
17
18 const std::string &path() const { return _path; }
19 load_state loadstate() const { return _loadstate; }
20 const audio_file_cptr data() const { return _data; }
21
22 const std::vector<float>& rendered() const;
23 // number of render samples per frame
24 double rsamplerate() const;
25
26 // samples packed the way saudio likes them
27 const std::vector<float>& packed() const;
28
29 int minframe() const override;
30 int maxframe() const override;
31
32 private:
33 void load_async();
34 std::vector<float> render_samples(double rsamplerate);
35
36 const std::string _path;
37 audio_file_ptr _data;
38 std::vector<float> _rhi;
39 std::vector<float> _rlo;
40 std::vector<float> _packed;
41 load_state _loadstate;
42 };
43 }
44
45 #endif
00 #include "qb.hpp"
1 #include "audionode.hpp"
12 #include "colors.hpp"
23 #include "nodeui.hpp"
34
5152 const ImVec2 origin = ImVec2(0, ImGui::GetItemRectMin().y);
5253 const ImVec2 corner =
5354 ImVec2(ImGui::GetWindowWidth(), ImGui::GetItemRectMax().y);
54 const double width = corner.x - origin.x;
55 const double scale = width / (s1 - s0);
55 const float width = corner.x - origin.x;
56 const float scale = width / (s1 - s0);
5657
5758 ImDrawList * const drawlist = ImGui::GetWindowDrawList();
5859 for (int64_t s = std::max(int64_t(1), s0 + 1);
5960 s <= s1 && s < (int64_t) r.size(); s++) {
6061 const ImVec2 a(origin.x + scale * (s - 1 - s0),
61 origin.y + rad * (1.0 - r[s - 1]));
62 origin.y + rad * (1.0f - r[s - 1]));
6263 const ImVec2 b(origin.x + scale * (s - s0),
63 origin.y + rad * (1.0 - r[s]));
64 origin.y + rad * (1.0f - r[s]));
6465 drawlist->AddLine(a, b, theme::colors[theme::color::waveform]);
6566 }
6667 }
00 #include "qb.hpp"
1 #include "audionode.hpp"
12 #include "colors.hpp"
23 #include "nodeui.hpp"
34 #include "task.hpp"
110111 }
111112
112113 void context::initaudio() {
114 const audio_node *audio = nullptr;
113115 for (const auto &n : _nodes) {
114116 if (const auto an = dynamic_cast<const audio_node *>(&(*n))) {
115117 if (an->loadstate().stage == load_state::loading) {
118120 if (an->loadstate().stage == load_state::failed) {
119121 continue;
120122 }
121 audiosource = an;
123 audio = an;
122124 break;
123125 }
124126 }
125 if (!audiosource) {
127 if (!audio) {
126128 return;
127129 }
128130
129131 saudio_desc d = {0};
130 d.sample_rate = audiosource->data()->getSampleRate();
131 d.num_channels = audiosource->data()->getNumChannels();
132 d.sample_rate = audio->data()->getSampleRate();
133 d.num_channels = audio->data()->getNumChannels();
132134
133135 saudio_setup(&d);
134136 audioinit = saudio_isvalid();
135137 if (!audioinit) {
136 audiosource = nullptr;
137138 ImGui::Text("could not initialize audio engine");
139 } else {
140 audiosource = audio;
138141 }
139142 }
140143
143146 return;
144147 }
145148
146 const int samplerate = audiosource->data()->getSampleRate();
149 const audio_node *audio = static_cast<const audio_node*>(audiosource);
150 const int samplerate = audio->data()->getSampleRate();
147151 const double sampleperframe = (double) samplerate / (double) _framerate;
148 const std::vector<float> &s = audiosource->packed();
152 const std::vector<float> &s = audio->packed();
149153
150154 if (!playing) {
151155 if ((int) playhead == playedframe) {
33 #include <memory>
44 #include <string>
55 #include <vector>
6
7 #include "AudioFile/AudioFile.h"
86
97 namespace qb {
108 enum class node_type {
5351 };
5452 using node_ptr = std::shared_ptr<node>;
5553
56 using audio_file = AudioFile<float>;
57 using audio_file_ptr = std::shared_ptr<audio_file>;
58 using audio_file_cptr = std::shared_ptr<const audio_file>;
59
60 struct audio_node : public node {
61 audio_node(const context *c, const std::string &path);
62 ~audio_node() override;
63
64 const std::string &path() const { return _path; }
65 load_state loadstate() const { return _loadstate; }
66 const audio_file_cptr data() const { return _data; }
67
68 const std::vector<float>& rendered() const;
69 // number of render samples per frame
70 double rsamplerate() const;
71
72 // samples packed the way saudio likes them
73 const std::vector<float>& packed() const;
74
75 int minframe() const override;
76 int maxframe() const override;
77
78 private:
79 void load_async();
80 std::vector<float> render_samples(double rsamplerate);
81
82 const std::string _path;
83 audio_file_ptr _data;
84 std::vector<float> _rhi;
85 std::vector<float> _rlo;
86 std::vector<float> _packed;
87 load_state _loadstate;
88 };
89
9054 struct context
9155 {
9256 context();
12387 int playedframe = -1;
12488 int64_t pushedsample = -1;
12589
126 const audio_node *audiosource = nullptr;
90 const node *audiosource = nullptr;
12791
12892 int _framerate = 24;
12993 std::vector<qb::node_ptr> _nodes;