diff main/MainWindow.cpp @ 116:99d65ba33c88

* More useful status bar text -- show the current play time and the extents of the visible area * Add update-i18n.sh to update the i18n/ts and qm files -- I can't get qmake to do the right thing now that the project file has been split up into several project files * Fix missing Q_OBJECTs, etc, reported by lupdate * Update Russian translation from AlexandrE
author Chris Cannam
date Wed, 07 Mar 2007 17:07:02 +0000
parents a46d68ae3c3e
children 8089a394829a
line wrap: on
line diff
--- a/main/MainWindow.cpp	Mon Mar 05 15:32:55 2007 +0000
+++ b/main/MainWindow.cpp	Wed Mar 07 17:07:02 2007 +0000
@@ -160,13 +160,13 @@
     connect(m_paneStack, SIGNAL(propertyStacksResized()),
             this, SLOT(propertyStacksResized()));
     connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
-            statusBar(), SLOT(showMessage(const QString &)));
+            this, SLOT(contextHelpChanged(const QString &)));
 
     m_overview = new Overview(frame);
     m_overview->setViewManager(m_viewManager);
     m_overview->setFixedHeight(40);
     connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
-            statusBar(), SLOT(showMessage(const QString &)));
+            this, SLOT(contextHelpChanged(const QString &)));
 
     m_panLayer = new WaveformLayer;
     m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
@@ -248,6 +248,18 @@
     connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
 	    this, SLOT(outputLevelsChanged(float, float)));
 
+    connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
+            this, SLOT(playbackFrameChanged(unsigned long)));
+
+    connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
+            this, SLOT(globalCentreFrameChanged(unsigned long)));
+
+    connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
+            this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
+
+    connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
+            this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
+
     connect(Preferences::getInstance(),
             SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
             this,
@@ -1699,15 +1711,17 @@
 }
 
 void
-MainWindow::currentPaneChanged(Pane *)
+MainWindow::currentPaneChanged(Pane *p)
 {
     updateMenuStates();
+    updateVisibleRangeDisplay(p);
 }
 
 void
-MainWindow::currentLayerChanged(Pane *, Layer *)
+MainWindow::currentLayerChanged(Pane *p, Layer *)
 {
     updateMenuStates();
+    updateVisibleRangeDisplay(p);
 }
 
 void
@@ -2407,6 +2421,13 @@
     return m_document->getMainModel();
 }
 
+const WaveFileModel *
+MainWindow::getMainModel() const
+{
+    if (!m_document) return 0;
+    return m_document->getMainModel();
+}
+
 void
 MainWindow::newSession()
 {
@@ -2418,7 +2439,7 @@
     Pane *pane = m_paneStack->addPane();
 
     connect(pane, SIGNAL(contextHelpChanged(const QString &)),
-            statusBar(), SLOT(showMessage(const QString &)));
+            this, SLOT(contextHelpChanged(const QString &)));
 
     if (!m_timeRulerLayer) {
 	m_timeRulerLayer = m_document->createMainModelLayer
@@ -3115,8 +3136,9 @@
 MainWindow::play()
 {
     if (m_playSource->isPlaying()) {
-	m_playSource->stop();
+        stop();
     } else {
+        playbackFrameChanged(m_viewManager->getPlaybackFrame());
 	m_playSource->play(m_viewManager->getPlaybackFrame());
     }
 }
@@ -3187,6 +3209,13 @@
 MainWindow::stop()
 {
     m_playSource->stop();
+
+    if (m_paneStack && m_paneStack->getCurrentPane()) {
+        updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
+    } else {
+        m_myStatusMessage = "";
+        statusBar()->showMessage("");
+    }
 }
 
 void
@@ -3313,7 +3342,7 @@
 	m_pane = m_mw->m_paneStack->addPane();
 
         connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
-                m_mw->statusBar(), SLOT(showMessage(const QString &)));
+                m_mw, SLOT(contextHelpChanged(const QString &)));
     } else {
 	m_mw->m_paneStack->showPane(m_pane);
     }
@@ -3612,6 +3641,94 @@
 }    
 
 void
+MainWindow::playbackFrameChanged(unsigned long frame)
+{
+    if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
+
+    RealTime now = RealTime::frame2RealTime
+        (frame, getMainModel()->getSampleRate());
+
+    if (now.sec == m_lastPlayStatusSec) return;
+
+    RealTime then = RealTime::frame2RealTime
+        (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
+
+    QString nowStr;
+    QString thenStr;
+    QString remainingStr;
+
+    if (then.sec > 10) {
+        nowStr = now.toSecText().c_str();
+        thenStr = then.toSecText().c_str();
+        remainingStr = (then - now).toSecText().c_str();
+        m_lastPlayStatusSec = now.sec;
+    } else {
+        nowStr = now.toText(true).c_str();
+        thenStr = then.toText(true).c_str();
+        remainingStr = (then - now).toText(true).c_str();
+    }        
+
+    m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
+        .arg(nowStr).arg(thenStr).arg(remainingStr);
+
+    statusBar()->showMessage(m_myStatusMessage);
+}
+
+void
+MainWindow::globalCentreFrameChanged(unsigned long frame)
+{
+    if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
+    Pane *p = 0;
+    if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
+    if (!p->getFollowGlobalPan()) return;
+    updateVisibleRangeDisplay(p);
+}
+
+void
+MainWindow::viewCentreFrameChanged(View *v, unsigned long frame)
+{
+    if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
+    Pane *p = 0;
+    if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
+    if (v == p) updateVisibleRangeDisplay(p);
+}
+
+void
+MainWindow::viewZoomLevelChanged(View *v, unsigned long zoom, bool locked)
+{
+    if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
+    Pane *p = 0;
+    if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
+    if (v == p) updateVisibleRangeDisplay(p);
+}
+
+void
+MainWindow::updateVisibleRangeDisplay(Pane *p) const
+{
+    if (!getMainModel() || !p) {
+        return;
+    }
+
+    RealTime start = RealTime::frame2RealTime
+        (p->getFirstVisibleFrame(), getMainModel()->getSampleRate());
+
+    RealTime end = RealTime::frame2RealTime
+        (p->getLastVisibleFrame(), getMainModel()->getSampleRate());
+
+    RealTime duration = end - start;
+
+    QString startStr, endStr, durationStr;
+    startStr = start.toText(true).c_str();
+    endStr = end.toText(true).c_str();
+    durationStr = duration.toText(true).c_str();
+
+    m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
+        .arg(startStr).arg(endStr).arg(durationStr);
+
+    statusBar()->showMessage(m_myStatusMessage);
+}
+
+void
 MainWindow::outputLevelsChanged(float left, float right)
 {
     m_fader->setPeakLeft(left);
@@ -4310,20 +4427,30 @@
     if (!w) return;
 
     if (w == m_fader) {
-        statusBar()->showMessage(tr("Adjust the master playback level"));
+        contextHelpChanged(tr("Adjust the master playback level"));
     } else if (w == m_playSpeed) {
-        statusBar()->showMessage(tr("Adjust the master playback speed"));
+        contextHelpChanged(tr("Adjust the master playback speed"));
     } else if (w == m_playSharpen && w->isEnabled()) {
-        statusBar()->showMessage(tr("Toggle transient sharpening for playback time scaling"));
+        contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
     } else if (w == m_playMono && w->isEnabled()) {
-        statusBar()->showMessage(tr("Toggle mono mode for playback time scaling"));
+        contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
     }
 }
 
 void
 MainWindow::mouseLeftWidget()
 {
-    statusBar()->showMessage("");
+    contextHelpChanged("");
+}
+
+void
+MainWindow::contextHelpChanged(const QString &s)
+{
+    if (s == "" && m_myStatusMessage != "") {
+        statusBar()->showMessage(m_myStatusMessage);
+        return;
+    }
+    statusBar()->showMessage(s);
 }
 
 void