Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / QtCollider / widgets / QcScopeShm.h
blobde258e5a02e205d25ae585164c5b23e468e73411
1 /************************************************************************
3 * Copyright 2010-2011 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of Qt GUI for SuperCollider.
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 ************************************************************************/
22 #ifndef QC_SCOPE_H
23 #define QC_SCOPE_H
25 #include "../QcHelper.h"
27 #include <SC_Types.h>
29 #include <QWidget>
31 // FIXME: Due to Qt bug #22829, moc can not process headers that include
32 // boost/type_traits/detail/has_binary_operator.hp from boost 1.48, so
33 // we have to wrap the shm interface into a separate class.
35 namespace QtCollider
37 class ScopeShm;
40 using QtCollider::ScopeShm;
42 class QcScopeShm : public QWidget, QcHelper
44 Q_OBJECT
45 Q_PROPERTY( int serverPort READ serverPort WRITE setServerPort );
46 Q_PROPERTY( int bufferNumber READ dummyInt WRITE setBufferNumber );
47 Q_PROPERTY( float xOffset READ dummyFloat WRITE setXOffset );
48 Q_PROPERTY( float yOffset READ dummyFloat WRITE setYOffset );
49 Q_PROPERTY( float xZoom READ dummyFloat WRITE setXZoom );
50 Q_PROPERTY( float yZoom READ dummyFloat WRITE setYZoom );
51 Q_PROPERTY( int style READ style WRITE setStyle );
52 Q_PROPERTY( VariantList waveColors READ dummyVariantList WRITE setWaveColors );
53 Q_PROPERTY( QColor background READ background WRITE setBackground );
54 Q_PROPERTY( int updateInterval READ updateInterval WRITE setUpdateInterval );
55 Q_PROPERTY( bool running READ running );
57 public:
58 QcScopeShm();
59 ~QcScopeShm();
60 int serverPort() const { return _srvPort; }
61 void setServerPort( int );
62 void setBufferNumber( int );
63 void setXOffset( float f ) { xOffset = f; }
64 void setYOffset( float f ) { yOffset = f; }
65 void setXZoom( float f ) { xZoom = f; }
66 void setYZoom( float f ) { yZoom = f; }
67 int style() const { return _style; }
68 void setStyle( int i ) { _style = i; }
69 void setWaveColors( const VariantList & colors );
70 QColor background() const { return _bkg; }
71 void setBackground( const QColor &c ) { _bkg = c; update(); }
72 int updateInterval() const;
73 void setUpdateInterval( int i );
74 bool running() const { return _running; }
75 QSize sizeHint() const { return QSize( 500, 300 ); }
76 QSize minimumSizeHint() const { return QSize( 50, 50 ); }
77 public Q_SLOTS:
78 void start();
79 void stop();
80 protected:
81 void resizeEvent ( QResizeEvent * );
82 void paintEvent ( QPaintEvent * );
83 private Q_SLOTS:
84 void updateScope();
85 private:
86 void connectSharedMemory( int port );
87 void initScopeReader( ScopeShm *, int index );
88 void paint1D( bool overlapped, int channels, int maxFrames, int frames, const QRect &area, QPainter & );
89 void paint2D( int channels, int maxFrames, int frames, const QRect &area, QPainter & );
91 int _srvPort;
92 int _scopeIndex;
94 ScopeShm *_shm;
96 bool _running;
97 float *_data;
98 uint _availableFrames;
100 QTimer *timer;
101 float xOffset;
102 float yOffset;
103 float xZoom;
104 float yZoom;
105 int _style;
106 QList<QColor> colors;
107 QColor _bkg;
109 QPixmap _pixmap;
112 #endif