summaryrefslogtreecommitdiffstats
path: root/sigmodr/SoundUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-02-23 11:20:47 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-02-23 11:20:47 -0500
commit7aff48012c3040a675543a0ff3d23af6cb8a8638 (patch)
tree6dd17b90d1f1c6ba9b0b7c5ddc40c2a849c25286 /sigmodr/SoundUI.cpp
parent25ec942048336dde5e1a17e6c75e15e4f8d8290d (diff)
downloadsigen-7aff48012c3040a675543a0ff3d23af6cb8a8638.tar.gz
sigen-7aff48012c3040a675543a0ff3d23af6cb8a8638.tar.xz
sigen-7aff48012c3040a675543a0ff3d23af6cb8a8638.zip
Started restructuring how sigmodr is built and moving things into libraries
Diffstat (limited to 'sigmodr/SoundUI.cpp')
-rw-r--r--sigmodr/SoundUI.cpp159
1 files changed, 0 insertions, 159 deletions
diff --git a/sigmodr/SoundUI.cpp b/sigmodr/SoundUI.cpp
deleted file mode 100644
index eac2a4e7..00000000
--- a/sigmodr/SoundUI.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
- *
- * 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-// Header include
-#include "SoundUI.h"
-
-// Sigmod includes
-#include "../sigmod/Sigmod.h"
-#include "../sigmod/Sound.h"
-
-// KDE includes
-#include <KFileDialog>
-#include <KMessageBox>
-#include <KUrl>
-
-// Qt includes
-#include <QtCore/QBuffer>
-#include <QtCore/QFile>
-#include <QtCore/QTime>
-
-// Phonon includes
-#include <Phonon/AudioOutput>
-#include <Phonon/MediaObject>
-
-Sigmodr::SoundUI::SoundUI(Sigmod::Sound* sound, QWidget* parent) :
- ObjectUI(parent),
- m_output(new Phonon::AudioOutput(Phonon::MusicCategory, this)),
- m_media(new Phonon::MediaObject(this)),
- m_buffer(new QBuffer)
-{
- setupUi(this);
- setObjects(sound, new Sigmod::Sound(*sound));
-}
-
-Sigmodr::SoundUI::~SoundUI()
-{
- delete m_media;
- delete m_buffer;
-}
-
-void Sigmodr::SoundUI::initGui()
-{
- Phonon::createPath(m_media, m_output);
- m_media->setTickInterval(100);
- seeker->setMediaObject(m_media);
- sliderVolume->setAudioOutput(m_output);
- connect(m_media, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
- connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged(Phonon::State, Phonon::State)));
- connect(buttonPlay, SIGNAL(clicked()), m_media, SLOT(play()));
- connect(buttonPause, SIGNAL(clicked()), m_media, SLOT(pause()));
- connect(buttonStop, SIGNAL(clicked()), m_media, SLOT(stop()));
- buttonPlay->setIcon(KIcon("media-playback-start"));
- buttonPause->setIcon(KIcon("media-playback-pause"));
- buttonStop->setIcon(KIcon("media-playback-stop"));
- buttonBrowse->setIcon(KIcon("document-open"));
-}
-
-void Sigmodr::SoundUI::refreshGui()
-{
- resetAudioData();
-}
-
-void Sigmodr::SoundUI::setGui()
-{
- varName->setText(qobject_cast<Sigmod::Sound*>(modified())->name());
-}
-
-void Sigmodr::SoundUI::apply()
-{
- *qobject_cast<Sigmod::Sound*>(original()) = *qobject_cast<Sigmod::Sound*>(modified());
- emit(changed(false));
-}
-
-void Sigmodr::SoundUI::discard()
-{
- *qobject_cast<Sigmod::Sound*>(modified()) = *qobject_cast<Sigmod::Sound*>(original());
- setGui();
- emit(changed(false));
-}
-
-void Sigmodr::SoundUI::on_varName_textChanged(const QString& name)
-{
- const int cursor = varName->cursorPosition();
- qobject_cast<Sigmod::Sound*>(modified())->setName(name);
- varName->setCursorPosition(cursor);
-}
-
-void Sigmodr::SoundUI::on_buttonBrowse_clicked()
-{
- QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///audio"), "audio/*|Audio files", this));
- if (file.open(QIODevice::ReadOnly))
- {
- qobject_cast<Sigmod::Sound*>(modified())->setData(file.readAll());
- file.close();
- resetAudioData();
- }
-}
-
-void Sigmodr::SoundUI::stateChanged(Phonon::State newState, Phonon::State oldState)
-{
- Q_UNUSED(oldState)
- switch (newState)
- {
- case Phonon::ErrorState:
- if (m_media->errorType() == Phonon::FatalError)
- KMessageBox::warningContinueCancel(this, "Fatal Error", m_media->errorString());
- else
- KMessageBox::warningContinueCancel(this, "Error", m_media->errorString());
- break;
- case Phonon::PlayingState:
- buttonPlay->setEnabled(false);
- buttonPause->setEnabled(true);
- buttonStop->setEnabled(true);
- break;
- case Phonon::StoppedState:
- buttonPlay->setEnabled(true);
- buttonPause->setEnabled(false);
- buttonStop->setEnabled(false);
- tick(0);
- break;
- case Phonon::PausedState:
- buttonPlay->setEnabled(true);
- buttonPause->setEnabled(false);
- buttonStop->setEnabled(true);
- break;
- default:
- break;
- }
-}
-
-void Sigmodr::SoundUI::resetAudioData()
-{
- m_media->stop();
- m_buffer->setData(qobject_cast<Sigmod::Sound*>(modified())->data());
- m_media->setCurrentSource(m_buffer);
- tick(0);
-}
-
-void Sigmodr::SoundUI::tick(qint64 time)
-{
- QTime currentTime(0, (time / 60000) % 60, (time / 1000) % 60, time % 1000);
- qint64 total = m_media->totalTime();
- QTime totalTime(0, (total / 60000) % 60, (total / 1000) % 60, total % 1000);
- label->setText(QString("%1 / %2").arg(currentTime.toString("mm:ss.zzz")).arg(totalTime.toString("mm:ss.zzz")));
-}