Browse Source

revised Lights for Component Library, removed constructor argument from ModuleWidget

tags/v0.3.0
Andrew Belt 7 years ago
parent
commit
a76a6e7f5e
13 changed files with 105 additions and 33 deletions
  1. +1
    -1
      Makefile
  2. +56
    -0
      include/components.hpp
  3. +1
    -0
      include/engine.hpp
  4. +5
    -4
      include/math.hpp
  5. +8
    -0
      include/rack.hpp
  6. +2
    -3
      include/scene.hpp
  7. +0
    -1
      include/util.hpp
  8. +5
    -2
      src/core/AudioInterface.cpp
  9. +3
    -1
      src/core/MidiInterface.cpp
  10. +2
    -2
      src/gui.cpp
  11. +4
    -1
      src/main.cpp
  12. +8
    -9
      src/widgets/Light.cpp
  13. +10
    -9
      src/widgets/ModuleWidget.cpp

+ 1
- 1
Makefile View File

@@ -38,7 +38,7 @@ LDFLAGS += \
-L$(HOME)/pkg/portaudio-r1891-build/lib/x64/ReleaseMinDependency -lportaudio_x64 \
-Wl,--export-all-symbols,--out-implib,libRack.a -mwindows
TARGET = Rack.exe
OBJECTS = Rack.res
# OBJECTS = Rack.res

%.res: %.rc
windres $^ -O coff -o $@


+ 56
- 0
include/components.hpp View File

@@ -4,6 +4,16 @@

namespace rack {

#define SCHEME_BLACK nvgRGB(0x00, 0x00, 0x00)
#define SCHEME_WHITE nvgRGB(0xff, 0xff, 0xff)
#define SCHEME_RED nvgRGB(0xed, 0x2c, 0x24)
#define SCHEME_ORANGE nvgRGB(0xf2, 0xb1, 0x20)
#define SCHEME_YELLOW nvgRGB(0xf9, 0xdf, 0x1c)
#define SCHEME_GREEN nvgRGB(0x90, 0xc7, 0x3e)
#define SCHEME_CYAN nvgRGB(0x22, 0xe6, 0xef)
#define SCHEME_BLUE nvgRGB(0x29, 0xb2, 0xef)
#define SCHEME_PURPLE nvgRGB(0xd5, 0x2b, 0xed)

////////////////////
// Knobs
////////////////////
@@ -113,6 +123,52 @@ struct CL1362 : BASE {
typedef CL1362<InputPort> InputPortCL1362;
typedef CL1362<OutputPort> OutputPortCL1362;

////////////////////
// Lights
////////////////////

struct ValueLight : Light {
float *value;
};

struct RedValueLight : ValueLight {
void step() {
float v = sqrtBipolar(getf(value));
color = nvgLerpRGBA(SCHEME_BLACK, SCHEME_RED, v);
}
};

struct GreenRedPolarityLight : ValueLight {
void step() {
float v = sqrtBipolar(getf(value));
if (v >= 0.0)
color = nvgLerpRGBA(SCHEME_BLACK, SCHEME_GREEN, v);
else
color = nvgLerpRGBA(SCHEME_BLACK, SCHEME_RED, -v);
}
};

template <typename BASE>
struct LargeLight : BASE {
LargeLight() {
this->box.size = Vec(20, 20);
}
};

template <typename BASE>
struct MediumLight : BASE {
MediumLight() {
this->box.size = Vec(12, 12);
}
};

template <typename BASE>
struct SmallLight : BASE {
SmallLight() {
this->box.size = Vec(8, 8);
}
};

////////////////////
// Misc
////////////////////


+ 1
- 0
include/engine.hpp View File

@@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include "util.hpp"


namespace rack {


+ 5
- 4
include/math.hpp View File

@@ -45,14 +45,11 @@ inline float quadraticBipolar(float x) {
}

inline float cubic(float x) {
// optimal with --fast-math
return x*x*x;
}

inline float quarticBipolar(float x) {
float x2 = x*x;
float x4 = x2*x2;
return x >= 0.0 ? x4 : -x4;
return x >= 0.0 ? x*x*x*x : -x*x*x*x;
}

inline float quintic(float x) {
@@ -60,6 +57,10 @@ inline float quintic(float x) {
return x*x*x*x*x;
}

inline float sqrtBipolar(float x) {
return x >= 0.0 ? sqrtf(x) : -sqrtf(-x);
}

inline float sincf(float x) {
if (x == 0.0)
return 1.0;


+ 8
- 0
include/rack.hpp View File

@@ -68,5 +68,13 @@ Screw *createScrew(Vec pos) {
return screw;
}

template <class TLight>
ValueLight *createValueLight(Vec pos, float *value) {
ValueLight *light = new TLight();
light->box.pos = pos;
light->value = value;
return light;
}


} // namespace rack

+ 2
- 3
include/scene.hpp View File

@@ -24,16 +24,15 @@ struct Scene;
struct Model;
struct ModuleWidget : OpaqueWidget {
Model *model = NULL;
// Eventually this should be replaced with a `moduleId` which will be used for inter-process communication between the gui world and the audio world.
/** Owns the module pointer */
Module *module = NULL;
// int moduleId;

std::vector<InputPort*> inputs;
std::vector<OutputPort*> outputs;
std::vector<ParamWidget*> params;

ModuleWidget(Module *module);
~ModuleWidget();
void setModule(Module *module);
// Convenience functions for adding special widgets (calls addChild())
void addInput(InputPort *input);
void addOutput(OutputPort *output);


+ 0
- 1
include/util.hpp View File

@@ -1,7 +1,6 @@
#pragma once

// Include most of the C standard library for convenience
// (C++ programmers will hate me)
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>


+ 5
- 2
src/core/AudioInterface.cpp View File

@@ -256,7 +256,8 @@ void AudioInterface::closeDevice() {
if (stream) {
PaError err;
streamRunning = false;
err = Pa_StopStream(stream);
err = Pa_AbortStream(stream);
// err = Pa_StopStream(stream);
if (err) {
fprintf(stderr, "Failed to stop audio stream: %s\n", Pa_GetErrorText(err));
}
@@ -390,7 +391,9 @@ struct BlockSizeChoice : ChoiceButton {
};


AudioInterfaceWidget::AudioInterfaceWidget() : ModuleWidget(new AudioInterface()) {
AudioInterfaceWidget::AudioInterfaceWidget() {
AudioInterface *module = new AudioInterface();
setModule(module);
box.size = Vec(15*8, 380);

{


+ 3
- 1
src/core/MidiInterface.cpp View File

@@ -221,7 +221,9 @@ struct MidiChoice : ChoiceButton {
};


MidiInterfaceWidget::MidiInterfaceWidget() : ModuleWidget(new MidiInterface()) {
MidiInterfaceWidget::MidiInterfaceWidget() {
MidiInterface *module = new MidiInterface();
setModule(module);
box.size = Vec(15*8, 380);

{


+ 2
- 2
src/gui.cpp View File

@@ -180,12 +180,12 @@ void guiInit() {
err = glfwInit();
assert(err);

#ifndef WINDOWS
// #ifndef WINDOWS
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
// #endif
window = glfwCreateWindow(1000, 750, gApplicationName.c_str(), NULL, NULL);
assert(window);
glfwMakeContextCurrent(window);


+ 4
- 1
src/main.cpp View File

@@ -4,7 +4,10 @@
#include <libgen.h>
#endif

#include "rack.hpp"
#include "engine.hpp"
#include "gui.hpp"
#include "scene.hpp"
#include "plugin.hpp"


using namespace rack;


+ 8
- 9
src/widgets/Light.cpp View File

@@ -6,10 +6,10 @@ namespace rack {

void Light::draw(NVGcontext *vg) {
NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5);
Vec r = box.size.div(2.0);
float radius = box.size.x / 2.0;

nvgBeginPath(vg);
nvgEllipse(vg, r.x, r.y, r.x - 1.0, r.y - 1.0);
nvgCircle(vg, radius, radius, radius);
nvgFillColor(vg, color);
nvgFill(vg);

@@ -17,18 +17,17 @@ void Light::draw(NVGcontext *vg) {
nvgStrokeColor(vg, colorOutline);
nvgStroke(vg);

// float radius = box.size.x / 2.0;
// NVGcolor icol, ocol;
// nvgGlobalCompositeOperation(vg, NVG_LIGHTER);
// NVGpaint paint;
// icol = color;
// icol.a = clampf(color.a / 10.0, 0.0, 1.0);
// ocol = color;
// NVGcolor icol = color;
// icol.a = 0.2;
// NVGcolor ocol = color;
// ocol.a = 0.0;
// float oradius = radius + 20.0;
// paint = nvgRadialGradient(vg, c.x, c.y, radius, oradius, icol, ocol);
// paint = nvgRadialGradient(vg, radius, radius, radius, oradius, icol, ocol);
// nvgFillPaint(vg, paint);
// nvgBeginPath(vg);
// nvgRect(vg, c.x - oradius, c.y - oradius, 2*oradius, 2*oradius);
// nvgRect(vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius);
// nvgFill(vg);
}



+ 10
- 9
src/widgets/ModuleWidget.cpp View File

@@ -5,20 +5,21 @@

namespace rack {

ModuleWidget::ModuleWidget(Module *module) {
this->module = module;
if (module) {
engineAddModule(module);
}
}

ModuleWidget::~ModuleWidget() {
// Make sure WireWidget destructors are called *before* removing `module` from the rack.
disconnectPorts();
setModule(NULL);
}

void ModuleWidget::setModule(Module *module) {
if (this->module) {
engineRemoveModule(this->module);
delete this->module;
}
if (module) {
engineRemoveModule(module);
delete module;
engineAddModule(module);
}
this->module = module;
}

void ModuleWidget::addInput(InputPort *input) {


Loading…
Cancel
Save