summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/tippercanoe/synaescope.cpp
blob: a95658b1b38a3452c097bda20c3dacf4d87e0bd3 (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
/* Synaescope - a pretty noatun visualization (based on P. Harrison's Synaesthesia)
   Copyright (C) 1997 Paul Francis Harrison <[email protected]>
                 2001 Charles Samuels <[email protected]>
   Copyright (C) 2001 Neil Stevens <[email protected]>

	this file is X11 source
 */

#include <noatun/conversion.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <tqframe.h>
#include <tqregexp.h>
#include <noatun/app.h>
#include "syna.h"
#include "synaescope.h"

extern "C"
{
	KDE_EXPORT Plugin* create_plugin()
	{
		TDEGlobal::locale()->insertCatalogue("tippecanoe");
		return new SynaeScope();
	}
}

SynaeScope::SynaeScope()
	: TQWidget(0, 0, WType_TopLevel | WStyle_DialogBorder | WRepaintNoErase | WMouseNoMask)
	, StereoScope(50)
	, Plugin()
{
	setSamples(bufferSize);
	mBuffer = new char[bufferSize * 16 * 2];
	setFixedSize(320, 240);
	setCaption(i18n("Tippecanoe - Noatun"));
	setIcon(SmallIcon("noatun"));
	show();
	embed = new QXEmbed(this);
	embed->move(0,0);
	embed->resize(320, 240);
	embed->show();
	embed->setFocus();
}

SynaeScope::~SynaeScope()
{
	connect(&process, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(processExited(TDEProcess *)));
	napp->pluginMenuRemove(pluginMenuItem);
}

void SynaeScope::init()
{
	connect(&process, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int)), this, TQT_SLOT(read(TDEProcess *, char *, int)));
	pluginMenuItem = napp->pluginMenuAdd(i18n("Toggle Tippecanoe"), TQT_TQOBJECT(this), TQT_SLOT(toggle(void)));

	process << TDEStandardDirs::findExe("noatuntippecanoe.bin");

	// Note that process.start() will fail if findExe fails, so there's no real need
	// for two separate checks.
	if(!process.start(TDEProcess::NotifyOnExit, (TDEProcess::Communication)(TDEProcess::Stdin | TDEProcess::Stdout)))
	{
		KMessageBox::error(0, i18n("Unable to start noatuntippecanoe.bin. Check your installation."));
		unload();
	}
	else
		start();

}

void SynaeScope::scopeEvent(float *left, float *right, int size)
{
	if(!isHidden() && process.isRunning())
	{
		Conversion::convertStereo2FloatToI16le((unsigned long)size, left, 
		                                       right, (unsigned char*)mBuffer);

		process.writeStdin((char *)mBuffer, bufferSize*2);
	}
}

void SynaeScope::read(TDEProcess *, char *buf, int)
{
	TQString num = TQString::fromLatin1(buf);
	num = num.left(num.find(TQRegExp("\\s")));
	id = num.toInt();
	embed->embed(id);
}

void SynaeScope::processExited(TDEProcess *)
{
	unload();
}

void SynaeScope::toggle(void)
{
	if(isHidden())
		show();
	else
		hide();
}

#include "synaescope.moc"