1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
23 #include "../QcWidgetFactory.h"
28 static QcWidgetFactory
<QcScope
> factory
;
39 memset( &buffer
, 0, sizeof(SndBuf
) );
40 timer
= new QTimer( this );
41 timer
->setInterval( 15 );
42 setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Expanding
);
43 connect( timer
, SIGNAL( timeout() ), this, SLOT( updateScope() ) );
51 void QcScope::setBufferNumber( int n
)
57 void QcScope::setWaveColors( const VariantList
& newColors
)
60 Q_FOREACH( QVariant var
, newColors
.data
) {
61 QColor color
= var
.value
<QColor
>();
62 if( !color
.isValid() )
63 colors
.append( QColor( 0,0,0 ) );
65 colors
.append( color
);
69 int QcScope::updateInterval() const {
70 return timer
->interval();
73 void QcScope::setUpdateInterval( int interval
) {
74 timer
->setInterval( qMax(0, interval
) );
77 int getScopeBuf( uint32 index
, SndBuf
*buf
, bool& changed
);
79 void QcScope::updateScope()
81 #ifndef NO_INTERNAL_SERVER
84 getScopeBuf( bufNum
, &buffer
, changed
);
86 //printf("channels: %i\n", buffer.channels);
92 inline void QcScope::setPoint( QPointF
& pt
,
93 float x
, float y
, float xRatio
, float yRatio
,
94 int xStart
, int yStart
)
96 pt
.setX( ((x
+ xOffset
) * xRatio
) + xStart
);
97 pt
.setY( yStart
- ((y
+ yOffset
) * yRatio
) );
100 void QcScope::paint1D( bool overlapped
, QPainter
& p
)
103 float xRatio
= xZoom
* area
.width() / (float )buffer
.frames
;
104 float yRatio
= yZoom
* area
.height() * 0.5;
105 if( !overlapped
) yRatio
/= buffer
.channels
;
111 for( c
= 0; c
< buffer
.channels
; c
++ ) {
113 if( c
< colors
.count() ) p
.setPen( colors
[c
] );
114 else p
.setPen( QColor(255,255,255) );
116 float yCenter
= area
.height() * 0.5;
118 yCenter
*= ( c
* 2 + 1);
119 yCenter
/= buffer
.channels
;
123 setPoint( pt1
, 0, buffer
.data
[c
], xRatio
, yRatio
, area
.x(), yCenter
);
125 for( f
= 1, s
= c
+ buffer
.channels
;
127 f
++, s
+= buffer
.channels
)
129 setPoint( pt2
, f
, buffer
.data
[s
], xRatio
, yRatio
, area
.x(), yCenter
);
130 p
.drawLine( pt1
, pt2
);
136 void QcScope::paint2D( QPainter
& p
)
138 if( colors
.count() ) p
.setPen( colors
[0] );
139 else p
.setPen( QColor(255,255,255) );
142 int minSize
= qMin( area
.width(), area
.height() );
143 float xRatio
= xZoom
* minSize
* 0.5;
144 float yRatio
= yZoom
* minSize
* 0.5;
145 QPoint center
= area
.center();
146 int centerY
= center
.y();
147 int centerX
= center
.x();
151 float *data
= buffer
.data
;
152 float y
= buffer
.channels
> 1 ? data
[1] : 0.f
;
154 setPoint( pt1
, data
[0], y
, xRatio
, yRatio
, centerX
, centerY
);
155 data
+= buffer
.channels
;
158 for( f
= 1; f
< buffer
.frames
; f
++, data
+= buffer
.channels
)
160 if( buffer
.channels
> 1 ) y
= data
[1];
161 setPoint( pt2
, data
[0], y
, xRatio
, yRatio
, centerX
, centerY
);
162 p
.drawLine( pt1
, pt2
);
167 void QcScope::paintEvent ( QPaintEvent
* event
)
173 p
.fillRect( area
, _bkg
);
175 if( buffer
.frames
== 0 ) return;
179 else if( style
== 1 )
181 else if( style
== 2 )