|
From: Tapio V. <aa...@us...> - 2011-02-24 11:37:56
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 24 11:45:31 2011 +0200
Hack-of-the-Year to get some synth on Windows.
---
editorapp.cc | 8 +++++++-
synth.hh | 14 ++++++++++++++
2 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 0018282..f8009a6 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -762,7 +762,7 @@ void EditorApp::playButton()
} else {
ui.cmdPlay->setText(tr("Play"));
ui.cmdPlay->setIcon(QIcon::fromTheme("media-playback-start", QIcon(":/icons/media-playback-start.png")));
- synth.reset();
+ on_chkSynth_clicked(false);
}
}
@@ -771,8 +771,14 @@ void EditorApp::on_chkSynth_clicked(bool checked)
if (checked && player && player->state() == Phonon::PlayingState) {
synth.reset(new Synth);
connect(synth.data(), SIGNAL(playBuffer(QByteArray)), this, SLOT(playBuffer(QByteArray)));
+#ifdef Q_OS_WIN
+ if (audioOutput) audioOutput->setVolume(0.25);
+#else
+ if (audioOutput) audioOutput->setVolume(0.75);
+#endif
} else if (!checked) {
synth.reset();
+ if (audioOutput) audioOutput->setVolume(1.0);
}
}
diff --git a/synth.hh b/synth.hh
index 5408bc1..5418acb 100644
--- a/synth.hh
+++ b/synth.hh
@@ -13,6 +13,10 @@
#include "notes.hh"
#include "notegraphwidget.hh"
#include "notelabel.hh"
+#ifdef Q_OS_WIN
+#include <QTemporaryFile>
+#include <QSound>
+#endif
#ifndef M_PI
@@ -180,12 +184,22 @@ class BufferPlayer: public QObject
Q_DISABLE_COPY(BufferPlayer);
public:
BufferPlayer(const QByteArray& ba, QObject *parent): QObject(parent), m_data(ba) {
+#ifdef Q_OS_WIN
+ QTemporaryFile wavfile;
+ if (wavfile.open()) {
+ QDataStream stream(&wavfile);
+ stream.writeRawData(ba.data(), ba.size());
+ QSound::play(wavfile.fileName());
+ }
+
+#else
m_player = Phonon::createPlayer(Phonon::MusicCategory);
m_player->setParent(this);
m_buffer = new QBuffer(&m_data, this);
m_player->setCurrentSource(m_buffer);
connect(m_player, SIGNAL(finished()), this, SLOT(finished()));
m_player->play();
+#endif
}
public slots:
|