// // Created by Bradley Austin Davis on 2015/11/13 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "RecordingScriptingInterface.h" #include #include #include #include #include #include #include #include "ScriptEngineLogging.h" using namespace recording; RecordingScriptingInterface::RecordingScriptingInterface() { _player = DependencyManager::get(); _recorder = DependencyManager::get(); } bool RecordingScriptingInterface::isPlaying() const { return _player->isPlaying(); } bool RecordingScriptingInterface::isPaused() const { return _player->isPaused(); } float RecordingScriptingInterface::playerElapsed() const { return _player->position(); } float RecordingScriptingInterface::playerLength() const { return _player->length(); } void RecordingScriptingInterface::loadRecording(const QString& filename) { using namespace recording; if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection, Q_ARG(QString, filename)); return; } ClipPointer clip = Clip::fromFile(filename); if (!clip) { qWarning() << "Unable to load clip data from " << filename; } _player->queueClip(clip); } void RecordingScriptingInterface::startPlaying() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection); return; } _player->play(); } void RecordingScriptingInterface::setPlayerVolume(float volume) { // FIXME } void RecordingScriptingInterface::setPlayerAudioOffset(float audioOffset) { // FIXME } void RecordingScriptingInterface::setPlayerTime(float time) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "setPlayerTime", Qt::BlockingQueuedConnection, Q_ARG(float, time)); return; } _player->seek(time); } void RecordingScriptingInterface::setPlayFromCurrentLocation(bool playFromCurrentLocation) { _playFromCurrentLocation = playFromCurrentLocation; } void RecordingScriptingInterface::setPlayerLoop(bool loop) { _player->loop(loop); } void RecordingScriptingInterface::setPlayerUseDisplayName(bool useDisplayName) { _useDisplayName = useDisplayName; } void RecordingScriptingInterface::setPlayerUseAttachments(bool useAttachments) { _useAttachments = useAttachments; } void RecordingScriptingInterface::setPlayerUseHeadModel(bool useHeadModel) { _useHeadModel = useHeadModel; } void RecordingScriptingInterface::setPlayerUseSkeletonModel(bool useSkeletonModel) { _useSkeletonModel = useSkeletonModel; } void RecordingScriptingInterface::pausePlayer() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "pausePlayer", Qt::BlockingQueuedConnection); return; } _player->pause(); } void RecordingScriptingInterface::stopPlaying() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection); return; } _player->stop(); } bool RecordingScriptingInterface::isRecording() const { return _recorder->isRecording(); } float RecordingScriptingInterface::recorderElapsed() const { return _recorder->position(); } void RecordingScriptingInterface::startRecording() { if (_recorder->isRecording()) { qCWarning(scriptengine) << "Recorder is already running"; return; } if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "startRecording", Qt::BlockingQueuedConnection); return; } _recorder->start(); } void RecordingScriptingInterface::stopRecording() { _recorder->stop(); _lastClip = _recorder->getClip(); _lastClip->seek(0); } void RecordingScriptingInterface::saveRecording(const QString& filename) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "saveRecording", Qt::BlockingQueuedConnection, Q_ARG(QString, filename)); return; } if (!_lastClip) { qWarning() << "There is no recording to save"; return; } recording::Clip::toFile(filename, _lastClip); } void RecordingScriptingInterface::loadLastRecording() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection); return; } if (!_lastClip) { qCDebug(scriptengine) << "There is no recording to load"; return; } _player->queueClip(_lastClip); _player->play(); }