From b13604f9682d3998d1d8bb2b96c1e4fd4efbbdf6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 19 Aug 2014 16:43:26 -0700 Subject: [PATCH] JS API for recording --- interface/src/Application.cpp | 14 ---------- interface/src/avatar/MyAvatar.cpp | 39 +++++++++++++++++++++------- interface/src/avatar/MyAvatar.h | 13 +++++++--- interface/src/renderer/Model.cpp | 6 +++++ interface/src/renderer/Model.h | 3 +++ libraries/avatars/src/AvatarData.cpp | 4 +-- 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 093f5e6610..072d798569 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1051,20 +1051,6 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_R: if (isShifted) { Menu::getInstance()->triggerOption(MenuOption::FrustumRenderMode); - } else if (isMeta) { - if (_myAvatar->isRecording()) { - _myAvatar->stopRecording(); - } else { - _myAvatar->startRecording(); - _audio.setRecorder(_myAvatar->getRecorder()); - } - } else { - if (_myAvatar->isPlaying()) { - _myAvatar->stopPlaying(); - } else { - _myAvatar->startPlaying(); - _audio.setPlayer(_myAvatar->getPlayer()); - } } break; case Qt::Key_Percent: diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index e1d8274993..d5dfc4fd50 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -507,17 +507,16 @@ bool MyAvatar::setJointReferential(int id, int jointIndex) { return false; } } - +QString recordingFile = "recording.rec"; bool MyAvatar::isRecording() const { return _recorder && _recorder->isRecording(); } -RecorderPointer MyAvatar::startRecording() { +void MyAvatar::startRecording() { if (!_recorder) { _recorder = RecorderPointer(new Recorder(this)); } _recorder->startRecording(); - return _recorder; } void MyAvatar::stopRecording() { @@ -526,19 +525,41 @@ void MyAvatar::stopRecording() { } } +void MyAvatar::saveRecording(QString filename) { + if (_recorder) { + _recorder->saveToFile(filename); + } +} + bool MyAvatar::isPlaying() const { return _player && _player->isPlaying(); } -PlayerPointer MyAvatar::startPlaying() { +void MyAvatar::loadRecording(QString filename) { if (!_player) { _player = PlayerPointer(new Player(this)); } - if (_recorder) { - _player->loadRecording(_recorder->getRecording()); - _player->startPlaying(); + + _player->loadFromFile(filename); +} + +void MyAvatar::loadLastRecording() { + if (!_recorder) { + return; } - return _player; + if (!_player) { + _player = PlayerPointer(new Player(this)); + } + + _player->loadRecording(_recorder->getRecording()); +} + +void MyAvatar::startPlaying() { + if (!_player) { + _player = PlayerPointer(new Player(this)); + } + + _player->startPlaying(); } void MyAvatar::stopPlaying() { @@ -955,7 +976,7 @@ void MyAvatar::clearJointsData() { for (int i = 0; i < _jointData.size(); ++i) { Avatar::clearJointData(i); if (QThread::currentThread() == thread()) { - _skeletonModel.clearJointState(i); + _skeletonModel.clearJointAnimationPriority(i); } } } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 2c1695a499..a298e02229 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -134,6 +134,10 @@ public: /// Renders a laser pointer for UI picking void renderLaserPointers(); glm::vec3 getLaserPointerTipPosition(const PalmData* palm); + + const RecorderPointer getRecorder() const { return _recorder; } + const PlayerPointer getPlayer() const { return _player; } + public slots: void goHome(); void increaseSize(); @@ -157,14 +161,15 @@ public slots: bool setModelReferential(int id); bool setJointReferential(int id, int jointIndex); - const RecorderPointer getRecorder() const { return _recorder; } bool isRecording() const; - RecorderPointer startRecording(); + void startRecording(); void stopRecording(); + void saveRecording(QString filename); - const PlayerPointer getPlayer() const { return _player; } bool isPlaying() const; - PlayerPointer startPlaying(); + void loadRecording(QString filename); + void loadLastRecording(); + void startPlaying(); void stopPlaying(); diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 290f9b5c6f..c955b902c9 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -700,6 +700,12 @@ void Model::clearJointState(int index) { } } +void Model::clearJointAnimationPriority(int index) { + if (index != -1 && index < _jointStates.size()) { + _jointStates[index]._animationPriority = 0.0f; + } +} + void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) { if (index != -1 && index < _jointStates.size()) { JointState& state = _jointStates[index]; diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 431d17bf92..66baaac90d 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -121,6 +121,9 @@ public: /// Clear the joint states void clearJointState(int index); + /// Clear the joint animation priority + void clearJointAnimationPriority(int index); + /// Sets the joint state at the specified index. void setJointState(int index, bool valid, const glm::quat& rotation = glm::quat(), float priority = 1.0f); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 9653999555..0e7d3228f9 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -687,7 +687,7 @@ QVector AvatarData::getJointRotations() const { if (QThread::currentThread() != thread()) { QVector result; QMetaObject::invokeMethod(const_cast(this), - "getJointRotation", Qt::BlockingQueuedConnection, + "getJointRotations", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QVector, result)); return result; } @@ -702,7 +702,7 @@ void AvatarData::setJointRotations(QVector jointRotations) { if (QThread::currentThread() != thread()) { QVector result; QMetaObject::invokeMethod(const_cast(this), - "setJointRotation", Qt::BlockingQueuedConnection, + "setJointRotations", Qt::BlockingQueuedConnection, Q_ARG(QVector, jointRotations)); } for (int i = 0; i < jointRotations.size(); ++i) {