more moving stuff around, no more warnings on msvc
haldean
1 year, 9 months ago
64 | 64 |
set(QB_SOURCES
|
65 | 65 |
launch.c
|
66 | 66 |
audionode.cpp
|
|
67 |
audionode.hpp
|
67 | 68 |
colors.cpp
|
68 | 69 |
colors.hpp
|
69 | 70 |
qb.cpp
|
|
76 | 77 |
task.hpp
|
77 | 78 |
AudioFile/AudioFile.h
|
78 | 79 |
)
|
|
80 |
if (MSVC)
|
|
81 |
add_compile_options(/EHsc)
|
|
82 |
endif()
|
79 | 83 |
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
|
80 | 84 |
add_executable(qb WIN32 ${QB_SOURCES})
|
81 | 85 |
else()
|
0 | 0 |
#include "qb.hpp"
|
|
1 |
#include "audionode.hpp"
|
1 | 2 |
#include "task.hpp"
|
|
3 |
|
2 | 4 |
#include "AudioFile/AudioFile.h"
|
3 | 5 |
#include "AudioFFT/AudioFFT.h"
|
4 | 6 |
|
|
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
|
0 | 0 |
#include "qb.hpp"
|
|
1 |
#include "audionode.hpp"
|
1 | 2 |
#include "colors.hpp"
|
2 | 3 |
#include "nodeui.hpp"
|
3 | 4 |
|
|
51 | 52 |
const ImVec2 origin = ImVec2(0, ImGui::GetItemRectMin().y);
|
52 | 53 |
const ImVec2 corner =
|
53 | 54 |
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);
|
56 | 57 |
|
57 | 58 |
ImDrawList * const drawlist = ImGui::GetWindowDrawList();
|
58 | 59 |
for (int64_t s = std::max(int64_t(1), s0 + 1);
|
59 | 60 |
s <= s1 && s < (int64_t) r.size(); s++) {
|
60 | 61 |
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]));
|
62 | 63 |
const ImVec2 b(origin.x + scale * (s - s0),
|
63 | |
origin.y + rad * (1.0 - r[s]));
|
|
64 |
origin.y + rad * (1.0f - r[s]));
|
64 | 65 |
drawlist->AddLine(a, b, theme::colors[theme::color::waveform]);
|
65 | 66 |
}
|
66 | 67 |
}
|
0 | 0 |
#include "qb.hpp"
|
|
1 |
#include "audionode.hpp"
|
1 | 2 |
#include "colors.hpp"
|
2 | 3 |
#include "nodeui.hpp"
|
3 | 4 |
#include "task.hpp"
|
|
110 | 111 |
}
|
111 | 112 |
|
112 | 113 |
void context::initaudio() {
|
|
114 |
const audio_node *audio = nullptr;
|
113 | 115 |
for (const auto &n : _nodes) {
|
114 | 116 |
if (const auto an = dynamic_cast<const audio_node *>(&(*n))) {
|
115 | 117 |
if (an->loadstate().stage == load_state::loading) {
|
|
118 | 120 |
if (an->loadstate().stage == load_state::failed) {
|
119 | 121 |
continue;
|
120 | 122 |
}
|
121 | |
audiosource = an;
|
|
123 |
audio = an;
|
122 | 124 |
break;
|
123 | 125 |
}
|
124 | 126 |
}
|
125 | |
if (!audiosource) {
|
|
127 |
if (!audio) {
|
126 | 128 |
return;
|
127 | 129 |
}
|
128 | 130 |
|
129 | 131 |
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();
|
132 | 134 |
|
133 | 135 |
saudio_setup(&d);
|
134 | 136 |
audioinit = saudio_isvalid();
|
135 | 137 |
if (!audioinit) {
|
136 | |
audiosource = nullptr;
|
137 | 138 |
ImGui::Text("could not initialize audio engine");
|
|
139 |
} else {
|
|
140 |
audiosource = audio;
|
138 | 141 |
}
|
139 | 142 |
}
|
140 | 143 |
|
|
143 | 146 |
return;
|
144 | 147 |
}
|
145 | 148 |
|
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();
|
147 | 151 |
const double sampleperframe = (double) samplerate / (double) _framerate;
|
148 | |
const std::vector<float> &s = audiosource->packed();
|
|
152 |
const std::vector<float> &s = audio->packed();
|
149 | 153 |
|
150 | 154 |
if (!playing) {
|
151 | 155 |
if ((int) playhead == playedframe) {
|
3 | 3 |
#include <memory>
|
4 | 4 |
#include <string>
|
5 | 5 |
#include <vector>
|
6 | |
|
7 | |
#include "AudioFile/AudioFile.h"
|
8 | 6 |
|
9 | 7 |
namespace qb {
|
10 | 8 |
enum class node_type {
|
|
53 | 51 |
};
|
54 | 52 |
using node_ptr = std::shared_ptr<node>;
|
55 | 53 |
|
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 | |
|
90 | 54 |
struct context
|
91 | 55 |
{
|
92 | 56 |
context();
|
|
123 | 87 |
int playedframe = -1;
|
124 | 88 |
int64_t pushedsample = -1;
|
125 | 89 |
|
126 | |
const audio_node *audiosource = nullptr;
|
|
90 |
const node *audiosource = nullptr;
|
127 | 91 |
|
128 | 92 |
int _framerate = 24;
|
129 | 93 |
std::vector<qb::node_ptr> _nodes;
|