git.haldean.org qb / 4af9ca7
switch to playhead+radius instead of min/max haldean 5 months ago
3 changed file(s) with 15 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
4444 const context *c = node->ctx();
4545 const int rad = 100;
4646 const double rsamplerate = node->rsamplerate();
47 const size_t s0 = floor(rsamplerate * c->vismin);
48 const size_t s1 = ceil(rsamplerate * c->vismax);
47 const int64_t s0 = (long) floor(rsamplerate * (c->playhead - c->visrad));
48 const int64_t s1 = (long) ceil(rsamplerate * (c->playhead + c->visrad));
4949
5050 ImGui::InvisibleButton("##empty", ImVec2(-1, 2 * rad));
5151 const ImVec2 origin = ImVec2(0, ImGui::GetItemRectMin().y);
5555 const double scale = width / (s1 - s0);
5656
5757 ImDrawList *drawlist = ImGui::GetWindowDrawList();
58 for (size_t s = s0 + 1; s <= s1 && s < r.size(); s++) {
58 for (int64_t s = std::max(int64_t(1), s0 + 1);
59 s <= s1 && s < (int64_t) r.size(); s++) {
5960 const ImVec2 a(origin.x + scale * (s - 1 - s0),
6061 origin.y + rad * (1.0 - r[s - 1]));
6162 const ImVec2 b(origin.x + scale * (s - s0),
2121 ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_NoDecoration);
2222
2323 if (ImGui::IsKeyPressed(SAPP_KEYCODE_L)) {
24 int delta = (int) ceil((vismax - vismin) * 0.02);
25 vismin += delta;
26 vismax += delta;
24 int delta = (int) ceil(visrad * 0.02);
25 playhead += delta;
2726 } else if (ImGui::IsKeyPressed(SAPP_KEYCODE_H)) {
28 int delta = (int) ceil((vismax - vismin) * 0.02);
29 delta = std::min(vismin, delta);
30 vismin -= delta;
31 vismax -= delta;
27 int delta = (int) ceil(visrad * 0.02);
28 playhead -= delta;
3229 }
3330
31 /*
3432 int minframe = 0, maxframe = 0;
3533 for (const auto &n : _nodes) {
3634 minframe = std::min(minframe, n->minframe());
3735 maxframe = std::max(maxframe, n->maxframe());
3836 }
3937 ImGui::DragIntRange2("visible", &vismin, &vismax, 1.0, minframe, maxframe);
38 */
4039
4140 for (const auto &n : _nodes) {
4241 draw_node(n);
6362 static constexpr int hires_frame_limit = 1000;
6463
6564 const std::vector<float>& audio_node::rendered() const {
66 int visframes = _c->vismax - _c->vismin;
65 int visframes = 2 * _c->visrad;
6766 return visframes > hires_frame_limit ? _rlo : _rhi;
6867 }
6968
7069 double audio_node::rsamplerate() const {
71 int visframes = _c->vismax - _c->vismin;
70 int visframes = 2 * _c->visrad;
7271 return (visframes > hires_frame_limit ? render_rate_lo : render_rate_hi);
7372 }
7473
9999 void frame(int width, int height);
100100 void shutdown();
101101
102 int vismin = 0;
103 int vismax = 240;
102 int playhead = 0;
103 int visrad = 240;
104104
105 // for ui animations
105106 uint32_t spinstep = 0;
106107
107108 private: