Skip to content

Commit 097e7f1

Browse files
committed
actually working knobs (WOAH)
1 parent 6b718e9 commit 097e7f1

File tree

12 files changed

+135
-49
lines changed

12 files changed

+135
-49
lines changed

daw/src/gui/debugui.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <string_view>
34
#include "clap/ext/params.h"
45
#include "clapeze/params/baseParameter.h"
56
#include "kitgui/controls/knob.h"
@@ -70,14 +71,16 @@ void DebugParam(TParamsFeature& feature) {
7071

7172
class BaseParamKnob : public kitgui::Knob {
7273
public:
73-
explicit BaseParamKnob(const clapeze::BaseParam& param, clap_id id) : mParam(param), mId(id) {
74+
explicit BaseParamKnob(const clapeze::BaseParam& param, clap_id id, std::string_view sceneNode)
75+
: mParam(param), mId(id), mSceneNode(sceneNode) {
7476
// TODO: we'll need to listen for rescans if names can ever change
7577
clap_param_info_t info;
7678
mParam.FillInformation(id, &info);
7779
mName = info.name;
7880
}
7981
~BaseParamKnob() override = default;
8082
clap_id GetParamId() const { return mId; }
83+
const std::string& GetSceneNode() const { return mSceneNode; }
8184

8285
protected:
8386
const std::string& GetName() const override { return mName; }
@@ -93,14 +96,9 @@ class BaseParamKnob : public kitgui::Knob {
9396
private:
9497
const clapeze::BaseParam& mParam;
9598
const clap_id mId;
99+
std::string mSceneNode;
96100
std::string mName{};
97101
};
98-
99-
/* Helper class for creating a knob based on a parameter*/
100-
template <typename TParamsFeature, TParamsFeature::Id id>
101-
class ParamKnob : kitgui::Knob {
102-
public:
103-
};
104102
} // namespace kitgui
105103

106104
#endif

daw/src/gui/kitguiFeature.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void KitguiFeature::Destroy() {
129129
mCtx.Destroy();
130130
sInitCount--;
131131
if (sInitCount <= 0) {
132+
// todo: deinit only once
132133
kitgui::Context::deinit();
133134
if (sTimerId) {
134135
mHost.CancelTimer(sTimerId);

daw/src/keysynth/keysynth.cpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#include <memory>
1414

1515
#include "descriptor.h"
16+
#include "kitdsp/math/util.h"
17+
#include "kitgui/context.h"
1618

1719
#if KITSBLIPS_ENABLE_GUI
1820
#include <imgui.h>
1921
#include <kitgui/app.h>
2022
#include "clapeze/ext/assets.h"
2123
#include "gui/debugui.h"
2224
#include "gui/kitguiFeature.h"
23-
#include "kitgui/controls/knob.h"
2425
#include "kitgui/gfx/scene.h"
2526
#endif
2627

@@ -294,18 +295,41 @@ class Processor : public clapeze::InstrumentProcessor<ParamsFeature::ProcessorHa
294295
class GuiApp : public kitgui::BaseApp {
295296
public:
296297
GuiApp(kitgui::Context& ctx, ParamsFeature& params)
297-
: kitgui::BaseApp(ctx), mParams(params), mScene(std::make_unique<kitgui::Scene>(ctx)) {
298-
// ctx.SetSizeConfig({1000, 600});
299-
ctx.SetClearColor(Magnum::Math::Color4(0.3f, 0.7f, 0.3f, 1.0f));
300-
}
298+
: kitgui::BaseApp(ctx), mParams(params), mScene(std::make_unique<kitgui::Scene>(ctx)) {}
301299
~GuiApp() = default;
302300

303301
void OnActivate() override {
304-
mScene->Load("assets/kitskeys.packed.glb");
302+
mScene->Load("assets/kitskeys.glb");
303+
// TODO: to update all this if the viewport changes
304+
mScene->SetViewport({600.0f, 400.0f});
305+
306+
struct KnobSetupInfo {
307+
Params param;
308+
std::string node;
309+
};
310+
const std::vector<KnobSetupInfo> knobs{
311+
{Params::PolyMode, "knob-mid-Davies-1900h"}, {Params::PolyCount, "knob-mid-Davies-1900h.001"},
312+
{Params::OscOctave, "knob-mid-Davies-1900h.003"}, {Params::OscTune, "knob-mid-Davies-1900h.004"},
313+
{Params::FilterCutoff, "knob-mid-Davies-1900h.006"}, {Params::FilterResonance, "knob-mid-Davies-1900h.005"},
314+
};
315+
305316
// TODO: data-driven
306-
clap_id id = static_cast<clap_id>(Params::OscTune);
307-
mKnobs.push_back(std::make_unique<kitgui::BaseParamKnob>(*mParams.GetBaseParam(id), id));
317+
for (const auto& knobInfo : knobs) {
318+
clap_id id = static_cast<clap_id>(knobInfo.param);
319+
mKnobs.push_back(std::make_unique<kitgui::BaseParamKnob>(*mParams.GetBaseParam(id), id, knobInfo.node));
320+
auto pos = mScene->GetObjectScreenPositionByName(knobInfo.node);
321+
if (pos) {
322+
// TODO: to size the knob appropriately we need the bounding range of the object and then transform the
323+
// corners of that into screen positions. for now, hardcoded.
324+
float w = 40.0f;
325+
float hw = w * 0.5f;
326+
mKnobs.back()->mPos = {pos->x() - hw, pos->y() - hw};
327+
mKnobs.back()->mWidth = w;
328+
mKnobs.back()->mShowDebug = false;
329+
}
330+
}
308331
}
332+
309333
void DebugParamList() {
310334
ImGui::TextWrapped("WIP keys synthesizer. don't tell anybody but this is a volca keys for ur computer");
311335

@@ -358,6 +382,9 @@ class GuiApp : public kitgui::BaseApp {
358382
if (knob->Update(raw)) {
359383
mParams.GetMainHandle().SetRawValue(id, raw);
360384
}
385+
// we assume the knob is at 12-o-clock, and knobs have 0.75turn(270deg) ranges
386+
constexpr float maxTurn = kitdsp::kPi * 2.0f * 0.75f;
387+
mScene->SetObjectRotationByName(knob->GetSceneNode(), (static_cast<float>(raw) - 0.5f) * -maxTurn);
361388
}
362389

363390
if (mShowDebugWindow) {
@@ -418,8 +445,10 @@ class Plugin : public InstrumentPlugin {
418445
ConfigFeature<clapeze::TomlStateFeature<ParamsFeature>>();
419446
#if KITSBLIPS_ENABLE_GUI
420447
ConfigFeature<clapeze::AssetsFeature>(GetHost());
421-
ConfigFeature<KitguiFeature>(GetHost(),
422-
[&params](kitgui::Context& ctx) { return std::make_unique<GuiApp>(ctx, params); });
448+
// aspect ratio 1.5
449+
kitgui::SizeConfig cfg{600, 400, true, true};
450+
ConfigFeature<KitguiFeature>(
451+
GetHost(), [&params](kitgui::Context& ctx) { return std::make_unique<GuiApp>(ctx, params); }, cfg);
423452
#endif
424453

425454
ConfigProcessor<Processor>(params.GetProcessorHandle());

kitgui/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ Tech design notes
2020
- complex/dynamic visual heirarchies and layouts
2121
- full DAW ui (that is to say, piano rolls and such)
2222

23+
### GLTF
24+
25+
We use gltf as our scene presentation format. your file should include
26+
27+
- a camera
28+
- any lighting you want
29+
30+
in addition to the subjects of your scene. we support
31+
32+
- png/jpeg/webp textures
33+
- PBR materials + lights
34+
35+
we don't support:
36+
37+
- any other kind of texture
38+
- mesh compression
39+
- transparent materials
40+
41+
but we'd like to! someday. To make your file manipulatable, export your scene with node names included. You can query based off of them.
42+
2343
### TODO
2444

2545
- Cocoa!!

kitgui/include/kitgui/controls/knob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Knob {
1313

1414
// defaults to showing for imgui display
1515
bool mShowDebug = true;
16-
// if not provided, uses imgui cursor
16+
// if not provided, uses imgui cursor. represents top left
1717
std::optional<Vector2> mPos = {};
1818
// if not provided, works off of imgui normal sizing
1919
std::optional<float> mWidth = {};

kitgui/include/kitgui/gfx/scene.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ class Scene {
2222
void Update();
2323
/** Draws the scene. */
2424
void Draw();
25+
/** Sets the viewport size, recalculating any cameras as needed. */
26+
void SetViewport(const kitgui::Vector2& size);
2527

2628
// These methods are added as needed, so no rhyme or reason to what's supported really
2729
void PlayAnimationByName(std::string_view name);
28-
void SetObjectRotationByName(std::string_view name, const kitgui::Quaternion& rot);
30+
void SetObjectRotationByName(std::string_view name, float angleRadians);
2931
std::optional<kitgui::Vector2> GetObjectScreenPositionByName(std::string_view name);
3032

3133
private:

kitgui/include/kitgui/types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ namespace kitgui {
88
// All magnum types that exist in the public interface should go through here instead
99
using Vector2 = Magnum::Vector2;
1010
using Color4 = Magnum::Color4;
11-
using Quaternion = Magnum::Quaternion;
1211
} // namespace kitgui

kitgui/src/gfx/lights.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "gfx/lights.h"
22

3-
// enable conversion to stl
3+
// IWYU pragma: begin_keep
44
#include <Corrade/Containers/OptionalStl.h>
55
#include <Corrade/Containers/PairStl.h>
66
#include <Corrade/Containers/StringStl.h>
7-
// done
7+
// IWYU pragma: end_keep
88

99
#include <Magnum/Math/Color.h>
1010
#include <Magnum/Trade/AbstractImporter.h>

kitgui/src/gfx/materials.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "gfx/materials.h"
22

3+
// IWYU pragma: begin_keep
34
#include <Corrade/Containers/OptionalStl.h>
45
#include <Corrade/Containers/PairStl.h>
56
#include <Corrade/Containers/StringStl.h>
7+
// IWYU pragma: end_keep
68

79
#include <Corrade/Containers/Array.h>
810
#include <Corrade/Utility/Algorithms.h>
@@ -11,14 +13,14 @@
1113
#include <Magnum/GL/Texture.h>
1214
#include <Magnum/GL/TextureFormat.h>
1315
#include <Magnum/ImageView.h>
14-
#include <Magnum/Math/Functions.h>
1516
#include <Magnum/PixelFormat.h>
1617
#include <Magnum/Trade/AbstractImporter.h>
1718
#include <Magnum/Trade/ImageData.h>
1819
#include <Magnum/Trade/MaterialData.h>
1920
#include <Magnum/Trade/PhongMaterialData.h>
2021
#include <Magnum/Trade/TextureData.h>
2122
#include <fmt/format.h>
23+
#include <cstddef>
2224
#include <optional>
2325
#include "log.h"
2426

@@ -33,15 +35,17 @@ void loadImage(Magnum::GL::Texture2D& texture, const Magnum::Trade::ImageData2D&
3335
const uint32_t channelCount = pixelFormatChannelCount(image.format());
3436
if (channelCount == 1 || channelCount == 2) {
3537
if (GL::Context::current().isExtensionSupported<GL::Extensions::ARB::texture_swizzle>()) {
36-
if (channelCount == 1)
38+
if (channelCount == 1) {
3739
texture.setSwizzle<'r', 'r', 'r', '1'>();
38-
else if (channelCount == 2)
40+
} else if (channelCount == 2) {
3941
texture.setSwizzle<'r', 'r', 'r', 'g'>();
42+
}
4043
} else {
4144
const PixelFormat imageFormat =
4245
pixelFormat(image.format(), channelCount == 2 ? 4 : 3, isPixelFormatSrgb(image.format()));
4346
Debug{} << "Texture swizzle not supported, expanding a" << image.format() << "image to" << imageFormat;
44-
const std::size_t rowStride = 4 * ((pixelFormatSize(imageFormat) * image.size().x() + 3) / 4);
47+
const std::size_t rowStride =
48+
static_cast<std::size_t>(4 * ((pixelFormatSize(imageFormat) * image.size().x() + 3) / 4));
4549
usedImageStorage = Containers::Array<char>{NoInit, std::size_t(rowStride * image.size().y())};
4650
const MutableImageView2D usedMutableImage{imageFormat, image.size(), usedImageStorage};
4751
usedImage = usedMutableImage;
@@ -53,11 +57,12 @@ void loadImage(Magnum::GL::Texture2D& texture, const Magnum::Trade::ImageData2D&
5357
usedMutableImage.pixels().expanded<2>(Containers::Size2D{dstChannelCount, channelSize});
5458
Utility::copy(src.exceptSuffix({0, 0, channelCount == 2 ? 1 : 0, 0}).broadcasted<2>(3),
5559
dst.exceptSuffix({0, 0, channelCount == 2 ? 1 : 0, 0}));
56-
if (channelCount == 2)
60+
if (channelCount == 2) {
5761
Utility::copy(src.exceptPrefix({0, 0, 1, 0}), dst.exceptPrefix({0, 0, 3, 0}));
62+
}
5863
}
5964
}
60-
GL::TextureFormat format;
65+
GL::TextureFormat format{};
6166
switch (usedImage.format()) {
6267
case PixelFormat::R8Unorm:
6368
case PixelFormat::RG8Unorm:
@@ -84,11 +89,10 @@ void loadImage(Magnum::GL::Texture2D& texture, const Magnum::Trade::ImageData2D&
8489
fmt::format("cannot load image of format {} ", static_cast<uint32_t>(usedImage.format())));
8590
return;
8691
}
87-
texture.setStorage(Math::log2(usedImage.size().max()) + 1, format, usedImage.size())
88-
.setSubImage(0, {}, usedImage)
89-
.generateMipmap();
92+
int32_t levels = static_cast<int32_t>(std::log2<int32_t>(usedImage.size().max()) + 1);
93+
texture.setStorage(levels, format, usedImage.size()).setSubImage(0, {}, usedImage).generateMipmap();
9094
} else {
91-
GL::TextureFormat format;
95+
GL::TextureFormat format{};
9296
switch (image.compressedFormat()) {
9397
case CompressedPixelFormat::Bc4RSnorm:
9498
case CompressedPixelFormat::Bc5RGSnorm:

kitgui/src/gfx/meshes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "gfx/meshes.h"
22

3+
// IWYU pragma: begin_keep
34
#include <Corrade/Containers/OptionalStl.h>
5+
// IWYU pragma: end_keep
6+
47
#include <Magnum/GL/Mesh.h>
58
#include <Magnum/MeshTools/Compile.h>
69
#include <Magnum/MeshTools/GenerateIndices.h>

0 commit comments

Comments
 (0)