summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/tyler/tyler.cpp
blob: 022f22a1407358eab176c819ca08a9ce8d1706d3 (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
// Copyright (C) 2001 Charles Samuels <charles@kde.org>
// Copyright (C) 2001 Neil Stevens <neil@qualityassistant.com>

#include "tyler.h"

#include <noatun/conversion.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <noatun/app.h>
#include <kdebug.h>

extern "C" Plugin *create_plugin()
{
	TDEGlobal::locale()->insertCatalogue("tyler");
	return new Tyler();
}

const int Tyler::bufferSize = 512;

Tyler::Tyler()
	: TQObject()
	, StereoScope(25)
	, Plugin()
{
	setSamples(bufferSize*2);
	mBuffer = new char[bufferSize * 16 * 2];
}

Tyler::~Tyler()
{
	delete [] mBuffer;
}

void Tyler::init()
{
	process << TDEStandardDirs::findExe("noatuntyler.bin");
	connect(&process, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(processExited(TDEProcess *)));

	// 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 noatuntyler.bin. Check your installation."));
		unload();
	}
	else
		start();

}

void Tyler::scopeEvent(float *left, float *right, int size)
{
	if(process.isRunning())
	{
		Conversion::convertMonoFloatTo16le((unsigned long)size, right,
		                                      (unsigned char*)mBuffer);

		Conversion::convertMonoFloatTo16le((unsigned long)size, left,
		                                      ((unsigned char*)mBuffer)+bufferSize*2);
		process.writeStdin((char *)mBuffer, bufferSize*2*2);
	}
}

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

#include "tyler.moc"