BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

Blank6.cpp (3402B)


      1 
      2 #include "Blank6.hpp"
      3 #include "skins.hpp"
      4 
      5 void Blank6::sampleRateChange() {
      6 	_rms.setSampleRate(APP->engine->getSampleRate());
      7 }
      8 
      9 void Blank6::processAll(const ProcessArgs& args) {
     10 	if (inputs[IN_INPUT].isConnected()) {
     11 		_haveLevel = true;
     12 		_level = _rms.next(inputs[IN_INPUT].getVoltageSum()) / 5.0f;
     13 	}
     14 	else {
     15 		_haveLevel = false;
     16 		_level = 0.0f;
     17 	}
     18 }
     19 
     20 struct Blank6Display : DisplayWidget {
     21 	Blank6* _module;
     22 	const char* _text;
     23 	std::string _fontPath;
     24 
     25 	Blank6Display(Blank6* module, const char* text)
     26 	: DisplayWidget(module)
     27 	, _module(module)
     28 	, _text(text)
     29 	, _fontPath(asset::plugin(pluginInstance, "res/fonts/audiowide.ttf"))
     30 	{
     31 	}
     32 
     33 	void drawOnce(const DrawArgs& args, bool screenshot, bool lit) override {
     34 		const Skins& skins = Skins::skins();
     35 		std::string skin = skins.defaultKey();
     36 		bool haveLevel = false;
     37 		float level = 0.0f;
     38 		if (lit) {
     39 			haveLevel = _module->_level;
     40 			level = _module->_level;
     41 			skin = _module->_skin;
     42 		}
     43 
     44 		NVGcolor textColor = nvgRGBA(0x33, 0x33, 0x33, 0xff);
     45 		NVGcolor bgColor = nvgRGBA(0xdd, 0xdd, 0xdd, 0xff);
     46 		const char* pathStroke = skins.skinCssValue(skin, "path-stroke");
     47 		if (pathStroke) {
     48 			textColor = Skins::cssColorToNVGColor(pathStroke, textColor);
     49 		}
     50 		NVGcolor bgTextColor = nvgRGBAf(0.5f * (textColor.r + bgColor.r), 0.5f * (textColor.g + bgColor.g), 0.5f * (textColor.b + bgColor.b), 1.0f);
     51 
     52 		const int split = 107;
     53 		drawText(args, 0, 0, box.size.x, split - 10, haveLevel, level, textColor, bgTextColor);
     54 		drawText(args, 0, split, box.size.x, box.size.y, haveLevel, level, textColor, bgTextColor);
     55 		drawText(args, 0, split - 10, box.size.x / 2 - 5, 10, haveLevel, level, textColor, bgTextColor);
     56 		drawText(args, box.size.x / 2 + 5, split - 10, box.size.x, 10, haveLevel, level, textColor, bgTextColor);
     57 	}
     58 
     59 	void drawText(const DrawArgs& args, int sx, int sy, int sw, int sh, bool haveLevel, float level, const NVGcolor& textColor, const NVGcolor& bgTextColor) {
     60 		std::shared_ptr<Font> font = APP->window->loadFont(_fontPath);
     61 		float offsetX = box.size.x / 2.0f;
     62 		float offsetY = box.size.y / 2.0f;
     63 		nvgSave(args.vg);
     64 		nvgScissor(args.vg, 0, 0, box.size.x, box.size.y);
     65 		nvgIntersectScissor(args.vg, sx, sy, sw, sh);
     66 		nvgTranslate(args.vg, offsetX, offsetY);
     67 		nvgRotate(args.vg, M_PI/2.0f);
     68 		nvgTranslate(args.vg, -offsetY, offsetX);
     69 		nvgFontSize(args.vg, 52.0f);
     70 		nvgFontFaceId(args.vg, font->handle);
     71 		nvgTextLetterSpacing(args.vg, 9.0f);
     72 		if (!haveLevel) {
     73 			nvgFillColor(args.vg, textColor);
     74 			nvgText(args.vg, 0, 0, _text, NULL);
     75 		}
     76 		else {
     77 			nvgFillColor(args.vg, bgTextColor);
     78 			nvgText(args.vg, 0, 0, _text, NULL);
     79 			if (level > 0.0001f) {
     80 				nvgFillColor(args.vg, decibelsToColor(amplitudeToDecibels(level)));
     81 				nvgText(args.vg, 0, 0, _text, NULL);
     82 			}
     83 		}
     84 		nvgRestore(args.vg);
     85 	}
     86 };
     87 
     88 struct Blank6Widget : BGModuleWidget {
     89 	static constexpr int hp = 6;
     90 
     91 	Blank6Widget(Blank6* module) {
     92 		setModule(module);
     93 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     94 		setPanel(box.size, "Blank6");
     95 		createScrews();
     96 
     97 		{
     98 			auto display = new Blank6Display(module, "BOGAUDIO");
     99 			display->box.pos = Vec(30, 32);
    100 			display->box.size = Vec(30, 316);
    101 			addChild(display);
    102 		}
    103 
    104 		addInput(createInput<BlankPort24>(Vec(33, 346), module, Blank6::IN_INPUT));
    105 	}
    106 };
    107 
    108 Model* modelBlank6 = bogaudio::createModel<Blank6, Blank6Widget>("Bogaudio-Blank6", "BLANK6", "6HP blank panel", "Blank");