--- gigedit/trunk/src/gigedit/dimregionedit.cpp 2019/02/02 17:53:36 3461 +++ gigedit/trunk/src/gigedit/dimregionedit.cpp 2019/10/01 16:21:28 3619 @@ -39,9 +39,6 @@ bool VelocityCurve::on_expose_event(GdkEventExpose* e) { const Cairo::RefPtr& cr = get_window()->create_cairo_context(); -#if 0 -} -#endif #else bool VelocityCurve::on_draw(const Cairo::RefPtr& cr) { #endif @@ -84,9 +81,6 @@ bool CrossfadeCurve::on_expose_event(GdkEventExpose* e) { const Cairo::RefPtr& cr = get_window()->create_cairo_context(); -#if 0 -} -#endif #else bool CrossfadeCurve::on_draw(const Cairo::RefPtr& cr) { #endif @@ -155,6 +149,138 @@ } +LFOGraph::LFOGraph() : dimreg(0) { + set_size_request(500, 100); +} + +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 +bool LFOGraph::on_expose_event(GdkEventExpose* e) { + const Cairo::RefPtr& cr = + get_window()->create_cairo_context(); +#else +bool LFOGraph::on_draw(const Cairo::RefPtr& cr) { +#endif + if (dimreg) { + const int w = get_width(); + const int h = get_height(); + const bool sensitive = is_sensitive(); + const bool signedRange = this->signedRange(); + const float visiblePeriods = 5.f; // such that minimum LFO frequency 0.1 Hz draws exactly a half period + + // short-hand functions for setting colors + auto setGrayColor = [&] { + cr->set_source_rgba(0.88, 0.88, 0.88, sensitive ? 1.0 : 0.3); + }; + auto setBlackColor = [&] { + cr->set_source_rgba(0, 0, 0, sensitive ? 1.0 : 0.3); + }; + auto setGreenColor = [&] { + cr->set_source_rgba(94/255.f, 219/255.f, 80/255.f, sensitive ? 1.0 : 0.3); + }; + auto setRedColor = [&] { + cr->set_source_rgba(255.f, 44/255.f, 44/255.f, sensitive ? 1.0 : 0.3); + }; + /*auto setBlueColor = [&] { + cr->set_source_rgba(53/255.f, 167/255.f, 255.f, sensitive ? 1.0 : 0.3); + };*/ + auto setOrangeColor = [&] { + cr->set_source_rgba(255.f, 177/255.f, 82/255.f, sensitive ? 1.0 : 0.3); + }; + + // draw horizontal center line (dashed gray) if LFO range is signed + if (signedRange) { + cr->move_to(0, h/2); + cr->line_to(w, h/2); + cr->set_line_width(2); + setGrayColor(); + cr->set_dash(std::vector{ 7, 5 }, 0 /*offset*/); + cr->stroke(); + } + + // draw a vertical line for each second + for (int period = 1; period < visiblePeriods; ++period) { + int x = float(w) / float(visiblePeriods) * period; + cr->move_to(x, 0); + cr->line_to(x, h); + cr->set_line_width(2); + setGrayColor(); + cr->set_dash(std::vector{ 5, 3 }, 0 /*offset*/); + cr->stroke(); + } + + // how many curves shall we draw, two or one? + const int runs = (hasControllerAssigned()) ? 2 : 1; + // only draw the two curves in dashed style if they're very close to each other + const bool dashedCurves = (runs == 2 && controllerDepth() < 63); + // draw the required amount of curves + for (int run = 0; run < runs; ++run) { + // setup the LFO generator with the relevant parameters + lfo.setup({ + .waveType = LinuxSampler::LFO::wave_sine, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029 + .rangeType = (signedRange) ? LinuxSampler::LFO::range_signed : LinuxSampler::LFO::range_unsigned, + .frequency = frequency(), + //.phase = TODO + .startLevel = startLevel(), + .internalDepth = internalDepth(), + .midiControllerDepth = controllerDepth(), + .flipPolarity = flipPolarity(), + .samplerate = w / visiblePeriods, + .maxValue = (signedRange) ? h/2 : h, + }); + // 1st curve reflects min. CC value, 2nd curve max. CC value + lfo.setMIDICtrlValue( (run == 0) ? 0 : 127 ); + + // the actual render/draw loop + for (int x = 0; x < w ; ++x) { + const float y = + (signedRange) ? + h/2 - lfo.render() : + h - lfo.render(); + if (x == 0) + cr->move_to(x, y); + else + cr->line_to(x, y); + } + cr->set_line_width( (frequency() <= 4.f) ? 2 : 1 ); + if (runs == 1) + setOrangeColor(); + else if (run == 0) + setGreenColor(); + else + setRedColor(); + if (dashedCurves) + cr->set_dash(std::vector{ 3, 3 }, (run == 0) ? 0 : 3 /*offset*/); + else + cr->set_dash(std::vector(), 0 /*offset*/); + cr->stroke(); + } + + // draw text legend + if (runs == 2) { + setRedColor(); + cr->move_to(2, 10); + cr->show_text("CC Max."); + + setGreenColor(); + cr->move_to(2, 23); + cr->show_text("CC Min."); + } else { // no controller assigned, internal depth only ... + setOrangeColor(); + cr->move_to(2, 10); + cr->show_text("Const. Depth"); + } + // draw text legend for each second ("1s", "2s", ...) + for (int period = 1; period < visiblePeriods; ++period) { + int x = float(w) / float(visiblePeriods) * period; + setBlackColor(); + cr->move_to(x - 13, h - 3); + cr->show_text(ToString(period) + "s"); + } + } + return true; +} + + EGStateOptions::EGStateOptions() : HBox(), label(_("May be cancelled: ")), checkBoxAttack(_("Attack")), @@ -438,7 +564,7 @@ sigc::mem_fun(*this, &DimRegionEdit::onButtonSelectSamplePressed) ); - for (int i = 0 ; i < 7 ; i++) { + for (int i = 0 ; i < 9 ; i++) { #if USE_GTKMM_GRID table[i] = new Gtk::Grid; table[i]->set_column_spacing(7); @@ -630,6 +756,28 @@ addProp(eLFO1Controller); addProp(eLFO1FlipPhase); addProp(eLFO1Sync); + { + Gtk::Frame* frame = new Gtk::Frame; + frame->add(lfo1Graph); + // on Gtk 3 there is no margin at all by default +#if GTKMM_MAJOR_VERSION >= 3 + frame->set_margin_top(12); + frame->set_margin_bottom(12); +#endif +#if USE_GTKMM_GRID + table[pageno]->attach(*frame, 1, rowno, 2); +#else + table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, + Gtk::SHRINK, Gtk::SHRINK); +#endif + rowno++; + } + eLFO1FlipPhase.signal_value_changed().connect( + sigc::mem_fun(lfo1Graph, &LFOGraph::queue_draw) + ); + + nextPage(); + addHeader(_("Crossfade")); addProp(eAttenuationController); addProp(eInvertAttenuationController); @@ -772,6 +920,9 @@ addProp(eEG2ControllerDecayInfluence); addProp(eEG2ControllerReleaseInfluence); addLine(eEG2StateOptions); + + nextPage(); + lLFO2 = addHeader(_("Filter Cutoff Oscillator (LFO2)")); addProp(eLFO2Frequency); addProp(eLFO2InternalDepth); @@ -791,6 +942,25 @@ addProp(eLFO2Controller); addProp(eLFO2FlipPhase); addProp(eLFO2Sync); + { + Gtk::Frame* frame = new Gtk::Frame; + frame->add(lfo2Graph); + // on Gtk 3 there is no margin at all by default +#if GTKMM_MAJOR_VERSION >= 3 + frame->set_margin_top(12); + frame->set_margin_bottom(12); +#endif +#if USE_GTKMM_GRID + table[pageno]->attach(*frame, 1, rowno, 2); +#else + table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, + Gtk::SHRINK, Gtk::SHRINK); +#endif + rowno++; + } + eLFO2FlipPhase.signal_value_changed().connect( + sigc::mem_fun(lfo2Graph, &LFOGraph::queue_draw) + ); nextPage(); @@ -818,6 +988,22 @@ } addProp(eLFO3Controller); addProp(eLFO3Sync); + { + Gtk::Frame* frame = new Gtk::Frame; + frame->add(lfo3Graph); + // on Gtk 3 there is no margin at all by default +#if GTKMM_MAJOR_VERSION >= 3 + frame->set_margin_top(12); + frame->set_margin_bottom(12); +#endif +#if USE_GTKMM_GRID + table[pageno]->attach(*frame, 1, rowno, 2); +#else + table[pageno]->attach(*frame, 1, 3, rowno, rowno + 1, + Gtk::SHRINK, Gtk::SHRINK); +#endif + rowno++; + } nextPage(); @@ -971,12 +1157,14 @@ sigc::mem_fun(*this, &DimRegionEdit::loop_infinite_toggled)); append_page(*table[0], _("Sample")); - append_page(*table[1], _("Amplitude (1)")); - append_page(*table[2], _("Amplitude (2)")); - append_page(*table[3], _("Filter (1)")); - append_page(*table[4], _("Filter (2)")); - append_page(*table[5], _("Pitch")); - append_page(*table[6], _("Misc")); + append_page(*table[1], _("Amp (1)")); + append_page(*table[2], _("Amp (2)")); + append_page(*table[3], _("Amp (3)")); + append_page(*table[4], _("Filter (1)")); + append_page(*table[5], _("Filter (2)")); + append_page(*table[6], _("Filter (3)")); + append_page(*table[7], _("Pitch")); + append_page(*table[8], _("Misc")); Settings::singleton()->showTooltips.get_proxy().signal_changed().connect( sigc::mem_fun(*this, &DimRegionEdit::on_show_tooltips_changed) @@ -1185,6 +1373,9 @@ release_curve.set_dim_region(d); cutoff_curve.set_dim_region(d); crossfade_curve.set_dim_region(d); + lfo1Graph.set_dim_region(d); + lfo2Graph.set_dim_region(d); + lfo3Graph.set_dim_region(d); set_sensitive(d); if (!d) return; @@ -1386,6 +1577,7 @@ eLFO2Controller.set_sensitive(sensitive); eLFO2FlipPhase.set_sensitive(sensitive); eLFO2Sync.set_sensitive(sensitive); + lfo2Graph.set_sensitive(sensitive); if (sensitive) { VCFCutoffController_changed(); VCFResonanceController_changed();