PageRenderTime 78ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/traverso/widgets/TransportConsoleWidget.cpp

#
C++ | 224 lines | 154 code | 38 blank | 32 comment | 14 complexity | 805c378a7bc42eb0589e69fd115d2717 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0
  1. /*
  2. Copyright (C) 2008 Nicola Doebelin
  3. This file is part of Traverso
  4. Traverso is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "TransportConsoleWidget.h"
  17. #include "Themer.h"
  18. #include "Sheet.h"
  19. #include "Utils.h"
  20. #include "AudioTrack.h"
  21. #include "ProjectManager.h"
  22. #include "Project.h"
  23. #include "TConfig.h"
  24. #include "Information.h"
  25. #include "TimeLineViewPort.h"
  26. #include <QAction>
  27. #include <QWidget>
  28. #include <QPushButton>
  29. #include <QGridLayout>
  30. #include <QEvent>
  31. #include <QFont>
  32. #include <QString>
  33. // Always put me below _all_ includes, this is needed
  34. // in case we run with memory leak detection enabled!
  35. #include "Debugger.h"
  36. TransportConsoleWidget::TransportConsoleWidget(QWidget* parent)
  37. : QToolBar(parent)
  38. {
  39. setEnabled(false);
  40. m_timeLabel = new QPushButton(this);
  41. m_timeLabel->setFocusPolicy(Qt::NoFocus);
  42. m_timeLabel->setStyleSheet(
  43. "color: lime;"
  44. "background-color: black;"
  45. "font: 19px;"
  46. "border: 2px solid gray;"
  47. "border-radius: 10px;"
  48. "padding: 0 8 0 8;");
  49. m_toStartAction = addAction(QIcon(":/skipleft"), tr("Skip to Start"), this, SLOT(to_start()));
  50. m_toLeftAction = addAction(QIcon(":/seekleft"), tr("Previous Snap Position"), this, SLOT(to_left()));
  51. m_recAction = addAction(QIcon(":/record"), tr("Record"), this, SLOT(rec_toggled()));
  52. m_playAction = addAction(QIcon(":/playstart"), tr("Play / Stop"), this, SLOT(play_toggled()));
  53. m_toRightAction = addAction(QIcon(":/seekright"), tr("Next Snap Position"), this, SLOT(to_right()));
  54. m_toEndAction = addAction(QIcon(":/skipright"), tr("Skip to End"), this, SLOT(to_end()));
  55. // addWidget(m_timeLabel);
  56. m_timeLabel->hide();
  57. m_recAction->setCheckable(true);
  58. m_playAction->setCheckable(true);
  59. m_lastSnapPosition = TimeRef();
  60. connect(&pm(), SIGNAL(projectLoaded(Project*)), this, SLOT(set_project(Project*)));
  61. connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(update_label()));
  62. update_layout();
  63. }
  64. void TransportConsoleWidget::set_project(Project* project)
  65. {
  66. m_project = project;
  67. if (m_project) {
  68. connect(m_project, SIGNAL(currentSessionChanged(TSession*)), this, SLOT(set_session(TSession*)));
  69. } else {
  70. m_updateTimer.stop();
  71. set_session(0);
  72. }
  73. }
  74. void TransportConsoleWidget::set_session(TSession* session)
  75. {
  76. Project* project = qobject_cast<Project*>(session);
  77. // if the view was changed to Project's session (mixer)
  78. // then keep the current active sheet!
  79. if (project) {
  80. return;
  81. }
  82. m_sheet = qobject_cast<Sheet*>(session);
  83. if (!m_sheet && session) {
  84. m_sheet = qobject_cast<Sheet*>(session->get_parent_session());
  85. }
  86. if (!m_sheet) {
  87. m_updateTimer.stop();
  88. setEnabled(false);
  89. update_label();
  90. return;
  91. }
  92. setEnabled(true);
  93. connect(m_sheet, SIGNAL(recordingStateChanged()), this, SLOT(update_recording_state()));
  94. connect(m_sheet, SIGNAL(transportStarted()), this, SLOT(transport_started()));
  95. connect(m_sheet, SIGNAL(transportStopped()), this, SLOT(transport_stopped()));
  96. connect(m_sheet, SIGNAL(transportPosSet()), this, SLOT(update_label()));
  97. update_label();
  98. }
  99. void TransportConsoleWidget::to_start()
  100. {
  101. m_sheet->skip_to_start();
  102. }
  103. void TransportConsoleWidget::to_left()
  104. {
  105. m_sheet->prev_skip_pos();
  106. }
  107. void TransportConsoleWidget::rec_toggled()
  108. {
  109. m_sheet->set_recordable();
  110. }
  111. void TransportConsoleWidget::play_toggled()
  112. {
  113. m_sheet->start_transport();
  114. }
  115. void TransportConsoleWidget::to_end()
  116. {
  117. m_sheet->skip_to_end();
  118. }
  119. void TransportConsoleWidget::to_right()
  120. {
  121. m_sheet->next_skip_pos();
  122. }
  123. void TransportConsoleWidget::transport_started()
  124. {
  125. // use an odd number for the update interval, because
  126. // a round number (e.g. 100) lets the last digit stay
  127. // the same most of the time, but not always, which
  128. // looks jerky
  129. m_updateTimer.start(123);
  130. m_playAction->setChecked(true);
  131. m_playAction->setIcon(QIcon(":/playstop"));
  132. m_recAction->setEnabled(false);
  133. // this is needed when the record button is pressed, but no track is armed.
  134. // uncheck the rec button in that case
  135. if (m_sheet && !m_sheet->is_recording()) {
  136. m_recAction->setChecked(false);
  137. }
  138. }
  139. void TransportConsoleWidget::transport_stopped()
  140. {
  141. m_updateTimer.stop();
  142. m_playAction->setChecked(false);
  143. m_playAction->setIcon(QIcon(":/playstart"));
  144. m_recAction->setEnabled(true);
  145. }
  146. void TransportConsoleWidget::update_recording_state()
  147. {
  148. if (!m_sheet)
  149. {
  150. return;
  151. }
  152. if (m_sheet->is_recording()) {
  153. QString recordFormat = config().get_property("Recording", "FileFormat", "wav").toString();
  154. int count = 0;
  155. foreach(AudioTrack* track, m_sheet->get_audio_tracks()) {
  156. if (track->armed()) {
  157. count++;
  158. }
  159. }
  160. info().information(tr("Recording to %1 Tracks, encoding format: %2").arg(count).arg(recordFormat));
  161. m_recAction->setChecked(true);
  162. } else {
  163. m_recAction->setChecked(false);
  164. }
  165. }
  166. void TransportConsoleWidget::update_label()
  167. {
  168. QString currentTime;
  169. if (!m_sheet) {
  170. currentTime = "";
  171. } else {
  172. currentTime = timeref_to_ms_2(m_sheet->get_transport_location());
  173. }
  174. m_timeLabel->setText(currentTime);
  175. }
  176. void TransportConsoleWidget::update_layout()
  177. {
  178. int iconsize = config().get_property("Themer", "transportconsolesize", "22").toInt();
  179. setIconSize(QSize(iconsize, iconsize));
  180. }
  181. //eof