summaryrefslogtreecommitdiffstats
path: root/arts/tools/fftscopeview.cpp
blob: 975b2943e0963089812c7a1b023d365e9f26d3e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*

    Copyright ( C ) 2000-2001 Stefan Westerfeld
                              <[email protected]>
                    2003 Arnold Krille <[email protected]>

    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; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    */

#include "fftscopeview.h"

#include <tqlayout.h>
#include <tqcursor.h>
#include <tqtimer.h>
#include <tdeaction.h>
#include <tdepopupmenu.h>
#include <kartswidget.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <kiconloader.h>

#include "artsactions.h"

using namespace std;
using namespace Arts;

FFTScopeView::FFTScopeView( SimpleSoundServer server, TQWidget* parent )
	: Template_ArtsView( parent )
	, server( server )
	, scopeData( 0 )
{
kdDebug()<<k_funcinfo<<endl;
	this->setCaption( i18n( "FFT Scope View" ) );
	this->setIcon( MainBarIcon( "artsfftscope", 32 ) );
	/*
	   create a stereo fft scope on the server and push it into the
	   effect chain
	*/
	{
		scopefx = DynamicCast( server.createObject( "Arts::StereoFFTScope" ) );
		assert( !scopefx.isNull() );
		scopefx.start();

		// put it into the effect chain
		effectID = server.outstack().insertBottom( scopefx,"FFT Scope" );
	}

	updateScopeData();
	TQBoxLayout * l = new TQHBoxLayout(  this );
	l->setAutoAdd( TRUE );

	for ( unsigned int i=0;i<scopeData->size();i++ )
	{
		LevelMeter tmp;
		tmp.count( 20 );
		scopeScales.push_back( tmp );
		scopeDraw.push_back( 0.0 );
		KArtsWidget *w = new KArtsWidget( tmp, this );
		aw.push_back( w );
	}

	l->activate();
	show();

	updatetimer = new TQTimer( this );
	updatetimer->start( 100 );
	connect( updatetimer,TQ_SIGNAL( timeout() ),this,TQ_SLOT( updateScope() ) );

	_artsactions = new ArtsActions( 0, 0, this );
	_moreBars = ArtsActions::actionMoreBars( this, TQ_SLOT( moreBars() ), 0 );
	_lessBars = ArtsActions::actionLessBars( this, TQ_SLOT( lessBars() ), 0 );
	_menu = new TDEPopupMenu( 0 );
	_moreBars->plug( _menu ); _lessBars->plug( _menu );
	_substyle = new TDEAction( i18n( "Substyle" ), "", TDEShortcut(), this, TQ_SLOT( substyle() ), this );
	_substyle->plug( _menu );
	_menu->insertItem( i18n("VU-Style"), _artsactions->stylemenu() );

	connect( _artsactions, TQ_SIGNAL( styleNormal() ), this, TQ_SLOT( styleNormalBars() ) );
	connect( _artsactions, TQ_SIGNAL( styleFire() ), this, TQ_SLOT( styleFireBars() ) );
	connect( _artsactions, TQ_SIGNAL( styleLine() ), this, TQ_SLOT( styleLineBars() ) );
	connect( _artsactions, TQ_SIGNAL( styleLED() ), this, TQ_SLOT( styleLEDs() ) );
	connect( _artsactions, TQ_SIGNAL( styleAnalog() ), this, TQ_SLOT( styleAnalog() ) );
	connect( _artsactions, TQ_SIGNAL( styleSmall() ), this, TQ_SLOT( styleSmall() ) );
}

FFTScopeView::~FFTScopeView() {
kdDebug()<<"FFTScopeView::~FFTScopeView()"<<endl;
	updatetimer->stop();
	for ( int i=int( aw.size() )-1; i>=0; i-- ) { scopeScales[ i ].hide(); delete aw[ i ]; aw.pop_back(); scopeScales.pop_back(); }
	server.outstack().remove( effectID );
kdDebug()<<"FFTScopeView is gone..."<<endl;
}

void FFTScopeView::updateScopeData() {
	if ( scopeData ) delete scopeData;
	scopeData = scopefx.scope();
}

void FFTScopeView::updateScope() {
	updateScopeData();

	for ( unsigned int i=0;i<scopeData->size();i++ )
	{
//		scopeDraw[ i ] /= 1.25;
//		if ( ( *scopeData )[ i ] > scopeDraw[ i ] ) scopeDraw[ i ] = ( *scopeData )[ i ];
		scopeDraw[ i ] = ( *scopeData )[ i ];
		scopeScales[ i ].invalue( scopeDraw[ i ] );
	}
}

void FFTScopeView::mousePressEvent( TQMouseEvent* ev ) {
	if ( TQt::RightButton == ev->button() /*|| TQt::LeftButton == ev->button()*/ )
		_menu->exec(  TQCursor::pos() );
}

void FFTScopeView::moreBars() {
	int bars = scopeScales[ 0 ].count() + 10;
	for ( unsigned int i=0;i<scopeData->size();i++ )
		scopeScales[ i ].count( bars );
}

void FFTScopeView::lessBars() {
	int bars = scopeScales[ 0 ].count() - 10;
	for ( unsigned int i=0;i<scopeData->size();i++ )
		scopeScales[ i ].count( bars );
}

void FFTScopeView::setStyle( Arts::LevelMeterStyle style ) {
	for ( uint i=0; i<scopeScales.size(); i++ )
		scopeScales[ i ].style( style );
}

void FFTScopeView::styleNormalBars() { setStyle( Arts::lmNormalBars ); }
void FFTScopeView::styleFireBars() { setStyle( Arts::lmFireBars ); }
void FFTScopeView::styleLineBars() { setStyle( Arts::lmLineBars ); }
void FFTScopeView::styleLEDs() { setStyle( Arts::lmLEDs ); }
void FFTScopeView::styleAnalog() { setStyle( Arts::lmAnalog ); }
void FFTScopeView::styleSmall() { setStyle( Arts::lmSmall ); }

#include <kinputdialog.h>

void FFTScopeView::substyle() {
	int _substyle = KInputDialog::getInteger( i18n("Substyle"), i18n("Please enter substyle:"), 0, 0, 10, 1, 0, this );
	for ( unsigned int i=0; i<scopeData->size(); i++ )
		scopeScales[ i ].substyle( _substyle );
}

#include "fftscopeview.moc"