1 /*  SpiralSynth
2  *  Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 // Stereo module
20 
21 #include "ScopeGUI.h"
22 #include "../SpiralSound/Output.h"
23 
24 #include <FL/fl_draw.H>
25 
ScopeWidget(int x,int y,int w,int h,const char * l)26 ScopeWidget::ScopeWidget(int x,int y,int w,int h,const char *l) :
27 Fl_Widget(x,y,w,h,l),
28 m_Channels(1)
29 {
30 }
31 
32 
draw()33 void ScopeWidget::draw()
34 {
35 	int ho=h()/2;
36 	fl_color(SpiralLoopsInfo::GUIBG_COLOUR);
37 	fl_rectf(x(), y(), w(), h());
38 	if (!m_Data) return;
39 
40 	int Value=0,NextValue=0;
41 
42 	fl_color(SpiralLoopsInfo::GUI_COLOUR+3);
43 	for(int n=0; n<SpiralLoopsInfo::BUFSIZE-1 && n<w(); n+=m_Channels)
44 	{
45 		Value = NextValue;
46 
47 		// stereo
48 		if (m_Channels==2)
49 		{
50 			NextValue = m_Data[n]+m_Data[n+1]/2;
51 		}
52 		else // mono
53 		{
54 			NextValue = m_Data[n];
55 		}
56 
57 		fl_line(x()+n,   y()+ho+Value/400.0f,
58 				x()+n+1, y()+ho+NextValue/400.0f);
59 	}
60 }
61 
ScopeGUI()62 ScopeGUI::ScopeGUI() : m_Bypass(false)
63 {
64 }
65 
Display(const short * data)66 void ScopeGUI::Display(const short *data)
67 {
68 	m_Scope->m_Data=data;
69 	if (!m_Bypass) m_Scope->redraw();
70 }
71 
CreateGUI(int xoff,int yoff,char * name)72 void ScopeGUI::CreateGUI(int xoff, int yoff, char *name)
73 {
74 	 Fl_Group* o = GUIScopeGroup = new Fl_Group(xoff, yoff, 225, 110, name);
75       o->type(1);
76 	  o->color(SpiralLoopsInfo::GUIBG2_COLOUR);
77 	  o->box(FL_UP_BOX);
78       o->labeltype(FL_ENGRAVED_LABEL);
79       o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
80 	  o->user_data((void*)(this));
81 
82 	  m_Scope = new ScopeWidget(xoff+5, yoff+20, 210, 85, "Scope");
83 
84 	  Bypass = new Fl_Button(175+xoff, 3+yoff, 40, 16, "Bypass");
85 	  Bypass->color(SpiralLoopsInfo::GUIBG2_COLOUR);
86       Bypass->labelsize(10);
87       Bypass->type(1);
88 	  Bypass->callback((Fl_Callback*)cb_Bypass);
89 
90       o->end();
91 }
92 
cb_Bypass_i(Fl_Button * o,void * v)93 void ScopeGUI::cb_Bypass_i(Fl_Button* o, void* v)
94 {m_Bypass=o->value();}
cb_Bypass(Fl_Button * o,void * v)95 void ScopeGUI::cb_Bypass(Fl_Button* o, void* v)
96 {((ScopeGUI*)(o->parent()->user_data()))->cb_Bypass_i(o,v);}
97