Browse Source

Middle click drag now sends an onScroll event in the object it is hovering, open UrlItem browser in new thread, use Module constructor for setting number of params/inputs/outputs

tags/v0.4.0
Andrew Belt 7 years ago
parent
commit
ffd8dde517
11 changed files with 82 additions and 41 deletions
  1. +8
    -0
      include/engine.hpp
  2. +10
    -1
      include/widgets.hpp
  3. +5
    -0
      src/app/RackScene.cpp
  4. +3
    -1
      src/app/RackWidget.cpp
  5. +7
    -13
      src/core/AudioInterface.cpp
  6. +7
    -13
      src/core/MidiInterface.cpp
  7. +0
    -1
      src/engine.cpp
  8. +5
    -0
      src/gui.cpp
  9. +4
    -1
      src/widgets/FramebufferWidget.cpp
  10. +0
    -11
      src/widgets/ScrollWidget.cpp
  11. +33
    -0
      src/widgets/ZoomWidget.cpp

+ 8
- 0
include/engine.hpp View File

@@ -17,6 +17,14 @@ struct Module {
/** For CPU usage */
float cpuTime = 0.0;

/** Deprecated, use constructor below this one */
Module() {}
/** Constructs Module with a fixed number of params, inputs, and outputs */
Module(int numParams, int numInputs, int numOutputs) {
params.resize(numParams);
inputs.resize(numInputs);
outputs.resize(numOutputs);
}
virtual ~Module() {}

/** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */


+ 10
- 1
include/widgets.hpp View File

@@ -369,10 +369,19 @@ struct ScrollWidget : OpaqueWidget {

ScrollWidget();
void step();
Widget *onMouseMove(Vec pos, Vec mouseRel);
bool onScrollOpaque(Vec scrollRel);
};

struct ZoomWidget : Widget {
float zoom = 1.0;
void draw(NVGcontext *vg);
Widget *onMouseDown(Vec pos, int button);
Widget *onMouseUp(Vec pos, int button);
Widget *onMouseMove(Vec pos, Vec mouseRel);
Widget *onHoverKey(Vec pos, int key);
Widget *onScroll(Vec pos, Vec scrollRel);
};

struct TextField : OpaqueWidget {
std::string text;
std::string placeholder;


+ 5
- 0
src/app/RackScene.cpp View File

@@ -29,9 +29,14 @@ static void checkVersion() {
RackScene::RackScene() {
scrollWidget = new ScrollWidget();
{
// ZoomWidget *zoomWidget = new ZoomWidget();
// zoomWidget->zoom = 0.8;
// scrollWidget->container->addChild(zoomWidget);

assert(!gRackWidget);
gRackWidget = new RackWidget();
scrollWidget->container->addChild(gRackWidget);
// zoomWidget->addChild(gRackWidget);
}
addChild(scrollWidget);



+ 3
- 1
src/app/RackWidget.cpp View File

@@ -1,5 +1,6 @@
#include <map>
#include <algorithm>
#include <thread>
#include "app.hpp"
#include "engine.hpp"
#include "plugin.hpp"
@@ -369,7 +370,8 @@ struct AddModuleMenuItem : MenuItem {
struct UrlItem : MenuItem {
std::string url;
void onAction() {
openBrowser(url);
std::thread t(openBrowser, url);
t.detach();
}
};



+ 7
- 13
src/core/AudioInterface.cpp View File

@@ -56,8 +56,13 @@ struct AudioInterface : Module {
// in device's sample rate
DoubleRingBuffer<Frame<8>, (1<<15)> inputSrcBuffer;

AudioInterface();
~AudioInterface();
AudioInterface() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
audioInit();
}
~AudioInterface() {
closeDevice();
}

void step();
void stepStream(const float *input, float *output, int numFrames);

@@ -117,17 +122,6 @@ struct AudioInterface : Module {
};


AudioInterface::AudioInterface() {
params.resize(NUM_PARAMS);
inputs.resize(NUM_INPUTS);
outputs.resize(NUM_OUTPUTS);
audioInit();
}

AudioInterface::~AudioInterface() {
closeDevice();
}

void AudioInterface::step() {
if (!stream)
return;


+ 7
- 13
src/core/MidiInterface.cpp View File

@@ -52,8 +52,13 @@ struct MidiInterface : Module {
bool retrigger = false;
bool retriggered = false;

MidiInterface();
~MidiInterface();
MidiInterface() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
midiInit();
}
~MidiInterface() {
setPortId(-1);
}

void step();

int getPortCount();
@@ -101,17 +106,6 @@ struct MidiInterface : Module {
};


MidiInterface::MidiInterface() {
params.resize(NUM_PARAMS);
inputs.resize(NUM_INPUTS);
outputs.resize(NUM_OUTPUTS);
midiInit();
}

MidiInterface::~MidiInterface() {
setPortId(-1);
}

void MidiInterface::step() {
if (stream) {
// Read MIDI events


+ 0
- 1
src/engine.cpp View File

@@ -25,7 +25,6 @@ static std::thread thread;
static VIPMutex vipMutex;

static std::vector<Module*> modules;
// Merely used for keeping track of which module inputs point to which module outputs, to prevent pointer mistakes and make the rack API more rigorous
static std::vector<Wire*> wires;

// Parameter interpolation


+ 5
- 0
src/gui.cpp View File

@@ -137,6 +137,11 @@ void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {
gHoveredWidget = hovered;
}
}
if (glfwGetMouseButton(gWindow, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS) {
// TODO
// Define a new global called gScrollWidget, which remembers the widget where middle-click was first pressed
gScene->onScroll(mousePos, mouseRel);
}
}

void cursorEnterCallback(GLFWwindow* window, int entered) {


+ 4
- 1
src/widgets/FramebufferWidget.cpp View File

@@ -71,8 +71,11 @@ void FramebufferWidget::step() {
}

void FramebufferWidget::draw(NVGcontext *vg) {
if (!internal->fb)
if (!internal->fb) {
// Bypass framebuffer cache entirely
// Widget::draw(vg);
return;
}

// Draw framebuffer image
nvgBeginPath(vg);


+ 0
- 11
src/widgets/ScrollWidget.cpp View File

@@ -35,17 +35,6 @@ void ScrollWidget::step() {
Widget::step();
}

Widget *ScrollWidget::onMouseMove(Vec pos, Vec mouseRel) {
if (glfwGetMouseButton(gWindow, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS) {
offset = offset.minus(mouseRel);
return this;
}

Widget *w = Widget::onMouseMove(pos, mouseRel);
if (w) return w;
return NULL;
}

bool ScrollWidget::onScrollOpaque(Vec scrollRel) {
offset = offset.minus(scrollRel);
return true;


+ 33
- 0
src/widgets/ZoomWidget.cpp View File

@@ -0,0 +1,33 @@
#include "widgets.hpp"


namespace rack {


void ZoomWidget::draw(NVGcontext *vg) {
nvgScale(vg, zoom, zoom);
Widget::draw(vg);
}

Widget *ZoomWidget::onMouseDown(Vec pos, int button) {
return Widget::onMouseDown(pos.div(zoom), button);
}

Widget *ZoomWidget::onMouseUp(Vec pos, int button) {
return Widget::onMouseUp(pos.div(zoom), button);
}

Widget *ZoomWidget::onMouseMove(Vec pos, Vec mouseRel) {
return Widget::onMouseMove(pos.div(zoom), mouseRel);
}

Widget *ZoomWidget::onHoverKey(Vec pos, int key) {
return Widget::onHoverKey(pos.div(zoom), key);
}

Widget *ZoomWidget::onScroll(Vec pos, Vec scrollRel) {
return Widget::onScroll(pos.div(zoom), scrollRel);
}


} // namespace rack

Loading…
Cancel
Save