/* ZynAddSubFX - a software synthesizer Fl_Oscilloscope.h - OSC Waveform View Copyright (C) 2016 Mark McCurry This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #pragma once #include "Fl_Osc_Pane.H" #include #include #include "Fl_Osc_Widget.H" #include "Fl_Osc_Pane.H" #include "Fl_Osc_Interface.h" #include "common.H" #include #include #include "../globals.h" class Fl_Osc_Group; //Consider merging in Fl_OscilSpectrum class Fl_Oscilloscope : public Fl_Box, public Fl_Osc_Widget { public: Fl_Oscilloscope(int x,int y, int w, int h, const char *label=0) :Fl_Box(x,y,w,h,label), Fl_Osc_Widget(this), smps(0), oscilsize(0), Overlay(NULL) { phase=64; box(FL_FLAT_BOX); bkgnd = fl_color_average( FL_BLACK, FL_BACKGROUND_COLOR, 0.5 ); } ~Fl_Oscilloscope(void) { delete[] smps; } void init(bool base_waveform_p) { ext = (base_waveform_p ? "base-waveform": "waveform"); osc->createLink("/oscilsize", this); osc->requestValue("/oscilsize"); assert(osc); oscRegister(ext.c_str()); } void update(void) { oscWrite(ext); } virtual void OSC_value(int smp) { if(smp == oscilsize) return; oscilsize = smp; delete []smps; smps = new float[oscilsize]; memset(smps, 0, oscilsize*sizeof(float)); } virtual void OSC_value(unsigned N, void *data) override { if(oscilsize == 0) OSC_value((int)N/4); assert(N==(unsigned)(oscilsize*4)); memcpy(smps, data, N); //normalize float max=0; for (int i=0;iactive_r()) fl_color(this->parent()->labelcolor()); else fl_color(this->parent()->color()); int GX=16;if (lxactive_r()) fl_color(this->parent()->selection_color()); else fl_color(this->parent()->labelcolor()); fl_color( fl_color_add_alpha( fl_color(), 127 ) ); if(smps) { int lw=2; fl_line_style(FL_SOLID,lw); fl_begin_line(); double ph=((phase-64.0)/128.0*oscilsize+oscilsize); for (int i=1;iredraw(); } //allows UI to manipuate phase of displayed waveform int phase; private: Fl_Osc_Pane *fetch_osc_pane(Fl_Widget *w) { if(!w) return NULL; Fl_Osc_Pane *pane = dynamic_cast(w->parent()); if(pane) return pane; return fetch_osc_pane(w->parent()); } float *smps; int oscilsize; Fl_Color bkgnd; public: Fl_Box *Overlay; };