2008-03-13 20:42:24 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#include "Panner.H"
|
|
|
|
|
2008-03-14 02:45:49 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2008-03-13 20:42:24 +01:00
|
|
|
/* 2D Panner widget. Supports various multichannel configurations. */
|
|
|
|
|
2008-03-13 22:55:13 +01:00
|
|
|
|
2008-03-13 20:42:24 +01:00
|
|
|
/* multichannel layouts, in degrees */
|
|
|
|
int Panner::_configs[][12] =
|
|
|
|
{
|
2008-03-13 22:55:13 +01:00
|
|
|
/* none, error condition? */
|
|
|
|
{ NONE },
|
|
|
|
/* mono, panner disabled */
|
|
|
|
{ NONE },
|
2008-03-13 20:42:24 +01:00
|
|
|
/* stereo */
|
2008-03-13 22:55:13 +01:00
|
|
|
{ L, R },
|
|
|
|
/* stereo + mono */
|
|
|
|
{ L, R, C },
|
2008-03-13 20:42:24 +01:00
|
|
|
/* quad */
|
2008-03-13 22:55:13 +01:00
|
|
|
{ FL, FR, RL, RR },
|
2008-03-13 20:42:24 +01:00
|
|
|
/* 5.1 */
|
2008-03-13 22:55:13 +01:00
|
|
|
{ FL, FR, RL, RR, C },
|
|
|
|
/* no such config */
|
|
|
|
{ NONE },
|
2008-03-13 20:42:24 +01:00
|
|
|
/* 7.1 */
|
2008-03-13 22:55:13 +01:00
|
|
|
{ FL, FR, RL, RR, C, L, R },
|
2008-03-13 20:42:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-14 02:45:49 +01:00
|
|
|
/* speaker symbol */
|
|
|
|
#define BP fl_begin_polygon()
|
|
|
|
#define EP fl_end_polygon()
|
|
|
|
#define BCP fl_begin_complex_polygon()
|
|
|
|
#define ECP fl_end_complex_polygon()
|
|
|
|
#define BL fl_begin_line()
|
|
|
|
#define EL fl_end_line()
|
|
|
|
#define BC fl_begin_loop()
|
|
|
|
#define EC fl_end_loop()
|
|
|
|
#define vv(x,y) fl_vertex(x,y)
|
|
|
|
|
|
|
|
static void draw_speaker ( Fl_Color col )
|
|
|
|
{
|
|
|
|
fl_color(col);
|
|
|
|
|
|
|
|
BP; vv(0.2,0.4); vv(0.6,0.4); vv(0.6,-0.4); vv(0.2,-0.4); EP;
|
|
|
|
BP; vv(-0.6,0.8); vv(0.2,0.0); vv(-0.6,-0.8); EP;
|
|
|
|
|
|
|
|
fl_color( fl_darker( col ) );
|
|
|
|
|
|
|
|
BC; vv(0.2,0.4); vv(0.6,0.4); vv(0.6,-0.4); vv(0.2,-0.4); EC;
|
|
|
|
BC; vv(-0.6,0.8); vv(0.2,0.0); vv(-0.6,-0.8); EC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
/** set X, Y, W, and H to the bounding box of point /p/ in screen coords */
|
|
|
|
void
|
|
|
|
Panner::point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const
|
2008-03-13 20:42:24 +01:00
|
|
|
{
|
2008-03-15 00:47:40 +01:00
|
|
|
int tx, ty, tw, th;
|
|
|
|
|
|
|
|
bbox( tx, ty, tw, th );
|
|
|
|
|
|
|
|
tw -= pw();
|
|
|
|
th -= ph();
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
float px, py;
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
p->axes( &px, &py );
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
*X = tx + ((tw / 2) * px + (tw / 2));
|
|
|
|
*Y = ty + ((th / 2) * py + (th / 2));
|
2008-03-13 22:03:00 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
*W = pw();
|
|
|
|
*H = ph();
|
|
|
|
}
|
|
|
|
|
|
|
|
Panner::Point *
|
|
|
|
Panner::event_point ( void )
|
|
|
|
{
|
2008-03-13 20:42:24 +01:00
|
|
|
for ( int i = _ins; i--; )
|
|
|
|
{
|
2008-03-15 00:47:40 +01:00
|
|
|
int px, py, pw, ph;
|
|
|
|
|
2008-03-13 20:42:24 +01:00
|
|
|
Point *p = &_points[ i ];
|
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
point_bbox( p, &px, &py, &pw, &ph );
|
2008-03-14 08:11:59 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
// printf( "%d, %d -- %d %d %d %d\n", Fl::event_x(), Fl::event_y(), px, py, pw, ph );
|
2008-03-14 08:11:59 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
if ( Fl::event_inside( px, py, pw, ph ) )
|
2008-03-13 20:42:24 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Panner::draw ( void )
|
|
|
|
{
|
2008-03-15 06:59:54 +01:00
|
|
|
draw_box();
|
|
|
|
// draw_box( FL_FLAT_BOX, x(), y(), w(), h(), FL_BLACK );
|
2008-03-13 20:42:24 +01:00
|
|
|
draw_label();
|
|
|
|
|
2008-03-15 06:59:54 +01:00
|
|
|
|
|
|
|
if ( _bypassed )
|
|
|
|
{
|
|
|
|
fl_color( 0 );
|
|
|
|
fl_font( FL_HELVETICA, 12 );
|
|
|
|
fl_draw( "(bypass)", x(), y(), w(), h(), FL_ALIGN_CENTER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-13 20:42:24 +01:00
|
|
|
int tw, th, tx, ty;
|
|
|
|
|
|
|
|
bbox( tx, ty, tw, th );
|
|
|
|
|
2008-03-14 08:19:00 +01:00
|
|
|
fl_push_clip( tx, ty, tw, th );
|
|
|
|
|
2008-03-14 02:45:49 +01:00
|
|
|
fl_color( FL_WHITE );
|
|
|
|
|
|
|
|
const int b = 10;
|
|
|
|
|
|
|
|
tx += b;
|
|
|
|
ty += b;
|
|
|
|
tw -= b * 2;
|
|
|
|
th -= b * 2;
|
|
|
|
|
|
|
|
fl_arc( tx, ty, tw, th, 0, 360 );
|
|
|
|
|
2008-03-13 22:03:00 +01:00
|
|
|
if ( _configs[ _outs ][0] >= 0 )
|
2008-03-13 20:42:24 +01:00
|
|
|
{
|
2008-03-13 22:03:00 +01:00
|
|
|
for ( int i = _outs; i--; )
|
|
|
|
{
|
|
|
|
int a = _configs[ _outs ][ i ];
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
Point p( 1.2f, (float)a );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
float px, py;
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
p.axes( &px, &py );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
fl_push_matrix();
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
const int bx = tx + ((tw / 2) * px + (tw / 2));
|
|
|
|
const int by = ty + ((th / 2) * py + (th / 2));
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
fl_translate( bx, by );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
fl_scale( 5, 5 );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
a = 90 - a;
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
fl_rotate( a );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
draw_speaker( FL_WHITE );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
fl_rotate( -a );
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
fl_pop_matrix();
|
2008-03-14 02:45:49 +01:00
|
|
|
|
2008-03-13 22:03:00 +01:00
|
|
|
}
|
2008-03-13 20:42:24 +01:00
|
|
|
}
|
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
/* ensure that points are drawn *inside* the circle */
|
2008-03-13 20:42:24 +01:00
|
|
|
|
|
|
|
for ( int i = _ins; i--; )
|
|
|
|
{
|
|
|
|
Point *p = &_points[ i ];
|
|
|
|
|
2008-03-14 08:19:00 +01:00
|
|
|
Fl_Color c = (Fl_Color)(10 + i);
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
int px, py, pw, ph;
|
|
|
|
point_bbox( p, &px, &py, &pw, &ph );
|
2008-03-14 08:11:59 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
/* draw point */
|
2008-03-14 08:19:00 +01:00
|
|
|
fl_color( c );
|
2008-03-15 00:47:40 +01:00
|
|
|
fl_pie( px, py, pw, ph, 0, 360 );
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
/* draw echo */
|
2008-03-14 08:19:00 +01:00
|
|
|
fl_color( c = fl_darker( c ) );
|
2008-03-15 00:47:40 +01:00
|
|
|
fl_arc( px - 5, py - 5, pw + 10, ph + 10, 0, 360 );
|
2008-03-14 08:19:00 +01:00
|
|
|
fl_color( c = fl_darker( c ) );
|
2008-03-15 00:47:40 +01:00
|
|
|
fl_arc( px - 10, py - 10, pw + 20, ph + 20, 0, 360 );
|
2008-03-14 08:19:00 +01:00
|
|
|
fl_color( c = fl_darker( c ) );
|
2008-03-15 00:47:40 +01:00
|
|
|
fl_arc( px - 30, py - 30, pw + 60, ph + 60, 0, 360 );
|
2008-03-14 08:19:00 +01:00
|
|
|
|
2008-03-14 23:29:10 +01:00
|
|
|
/* draw number */
|
2008-03-13 20:42:24 +01:00
|
|
|
char pat[4];
|
|
|
|
snprintf( pat, 4, "%d", i + 1 );
|
|
|
|
|
|
|
|
fl_color( FL_BLACK );
|
2008-03-15 00:47:40 +01:00
|
|
|
fl_font( FL_HELVETICA, ph + 2 );
|
|
|
|
fl_draw( pat, px + 1, py + 1, pw - 1, ph - 1, FL_ALIGN_CENTER );
|
2008-03-14 23:29:10 +01:00
|
|
|
|
|
|
|
/* draw line */
|
|
|
|
|
|
|
|
/* fl_color( FL_WHITE ); */
|
|
|
|
/* fl_line( bx + pw() / 2, by + ph() / 2, tx + (tw / 2), ty + (th / 2) ); */
|
|
|
|
|
2008-03-13 20:42:24 +01:00
|
|
|
}
|
2008-03-14 08:19:00 +01:00
|
|
|
|
|
|
|
fl_pop_clip();
|
2008-03-13 20:42:24 +01:00
|
|
|
}
|
|
|
|
|
2008-03-15 06:59:54 +01:00
|
|
|
/* return the current gain setting for the path in/out */
|
2008-03-20 02:06:28 +01:00
|
|
|
Panner::Point
|
|
|
|
Panner::point( int i )
|
2008-03-15 06:59:54 +01:00
|
|
|
{
|
2008-03-20 02:06:28 +01:00
|
|
|
return _points[ i ];
|
2008-03-15 06:59:54 +01:00
|
|
|
}
|
2008-03-13 20:42:24 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
Panner::handle ( int m )
|
|
|
|
{
|
|
|
|
static Point *drag;
|
|
|
|
|
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
|
|
|
|
case FL_PUSH:
|
2008-03-15 06:59:54 +01:00
|
|
|
|
|
|
|
if ( Fl::event_button2() )
|
2008-03-13 20:42:24 +01:00
|
|
|
{
|
2008-03-15 06:59:54 +01:00
|
|
|
_bypassed = ! _bypassed;
|
|
|
|
redraw();
|
|
|
|
return 0;
|
2008-03-13 20:42:24 +01:00
|
|
|
}
|
2008-03-15 06:59:54 +01:00
|
|
|
else if ( Fl::event_button1() && ( drag = event_point() ) )
|
|
|
|
return 1;
|
2008-03-13 20:42:24 +01:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
case FL_RELEASE:
|
|
|
|
drag = NULL;
|
|
|
|
return 1;
|
|
|
|
case FL_DRAG:
|
|
|
|
{
|
|
|
|
float X = Fl::event_x() - x();
|
|
|
|
float Y = Fl::event_y() - y();
|
|
|
|
|
2008-03-15 00:47:40 +01:00
|
|
|
int tx, ty, tw, th;
|
|
|
|
bbox( tx, ty, tw, th );
|
2008-03-14 08:11:59 +01:00
|
|
|
|
2008-03-20 02:06:28 +01:00
|
|
|
/* if ( _outs < 3 ) */
|
|
|
|
/* drag->angle( (float)(X / (tw / 2)) - 1.0f, 0.0f ); */
|
|
|
|
/* else */
|
2008-03-15 06:59:54 +01:00
|
|
|
drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f );
|
2008-03-13 20:42:24 +01:00
|
|
|
|
2008-03-15 04:40:48 +01:00
|
|
|
|
2008-03-20 02:06:28 +01:00
|
|
|
printf( "%f %f\n", drag->a, drag->d );
|
2008-03-14 06:37:10 +01:00
|
|
|
|
2008-03-13 20:42:24 +01:00
|
|
|
redraw();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|