comparison framework/MainWindowBase.cpp @ 166:2c2029007618

* "ffwd-similar" * stop when ffwding to end
author Chris Cannam
date Tue, 03 Mar 2009 21:48:03 +0000
parents 07d8dac78edc
children 875a21ad7a95
comparison
equal deleted inserted replaced
165:0bd09fb9e584 166:2c2029007618
2028 } 2028 }
2029 2029
2030 } else { 2030 } else {
2031 2031
2032 size_t resolution = 0; 2032 size_t resolution = 0;
2033 if (pane) frame = pane->alignFromReference(frame);
2033 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(), 2034 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
2034 frame, resolution, Layer::SnapRight)) { 2035 frame, resolution, Layer::SnapRight)) {
2035 if (pane) frame = pane->alignToReference(frame); 2036 if (pane) frame = pane->alignToReference(frame);
2036 } else { 2037 } else {
2037 frame = getMainModel()->getEndFrame(); 2038 frame = getMainModel()->getEndFrame();
2043 if (m_viewManager->getPlaySelectionMode()) { 2044 if (m_viewManager->getPlaySelectionMode()) {
2044 frame = m_viewManager->constrainFrameToSelection(size_t(frame)); 2045 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
2045 } 2046 }
2046 2047
2047 m_viewManager->setPlaybackFrame(frame); 2048 m_viewManager->setPlaybackFrame(frame);
2049
2050 if (frame == getMainModel()->getEndFrame() &&
2051 m_playSource &&
2052 m_playSource->isPlaying() &&
2053 !m_viewManager->getPlayLoopMode()) {
2054 stop();
2055 }
2048 } 2056 }
2049 2057
2050 void 2058 void
2051 MainWindowBase::ffwdEnd() 2059 MainWindowBase::ffwdEnd()
2052 { 2060 {
2063 if (m_viewManager->getPlaySelectionMode()) { 2071 if (m_viewManager->getPlaySelectionMode()) {
2064 frame = m_viewManager->constrainFrameToSelection(frame); 2072 frame = m_viewManager->constrainFrameToSelection(frame);
2065 } 2073 }
2066 2074
2067 m_viewManager->setPlaybackFrame(frame); 2075 m_viewManager->setPlaybackFrame(frame);
2076 }
2077
2078 void
2079 MainWindowBase::ffwdSimilar()
2080 {
2081 if (!getMainModel()) return;
2082
2083 Layer *layer = getSnapLayer();
2084 if (!layer) { ffwd(); return; }
2085
2086 Pane *pane = m_paneStack->getCurrentPane();
2087 size_t sr = getMainModel()->getSampleRate();
2088
2089 int frame = m_viewManager->getPlaybackFrame();
2090
2091 size_t resolution = 0;
2092 if (pane) frame = pane->alignFromReference(frame);
2093 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
2094 frame, resolution, Layer::SnapRight)) {
2095 if (pane) frame = pane->alignToReference(frame);
2096 } else {
2097 frame = getMainModel()->getEndFrame();
2098 }
2099
2100 if (frame < 0) frame = 0;
2101
2102 if (m_viewManager->getPlaySelectionMode()) {
2103 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
2104 }
2105
2106 m_viewManager->setPlaybackFrame(frame);
2107
2108 if (frame == getMainModel()->getEndFrame() &&
2109 m_playSource &&
2110 m_playSource->isPlaying() &&
2111 !m_viewManager->getPlayLoopMode()) {
2112 stop();
2113 }
2068 } 2114 }
2069 2115
2070 void 2116 void
2071 MainWindowBase::rewind() 2117 MainWindowBase::rewind()
2072 { 2118 {
2084 // the prior point instead of the immediately neighbouring one 2130 // the prior point instead of the immediately neighbouring one
2085 if (m_playSource && m_playSource->isPlaying()) { 2131 if (m_playSource && m_playSource->isPlaying()) {
2086 RealTime ct = RealTime::frame2RealTime(frame, sr); 2132 RealTime ct = RealTime::frame2RealTime(frame, sr);
2087 ct = ct - RealTime::fromSeconds(0.25); 2133 ct = ct - RealTime::fromSeconds(0.25);
2088 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime; 2134 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
2089 // std::cerr << "rewind: frame " << frame << " -> ";
2090 frame = RealTime::realTime2Frame(ct, sr); 2135 frame = RealTime::realTime2Frame(ct, sr);
2091 // std::cerr << frame << std::endl;
2092 } 2136 }
2093 2137
2094 if (!layer) { 2138 if (!layer) {
2095 2139
2096 frame = RealTime::realTime2Frame 2140 frame = RealTime::realTime2Frame
2100 } 2144 }
2101 2145
2102 } else { 2146 } else {
2103 2147
2104 size_t resolution = 0; 2148 size_t resolution = 0;
2149 if (pane) frame = pane->alignFromReference(frame);
2105 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(), 2150 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
2106 frame, resolution, Layer::SnapLeft)) { 2151 frame, resolution, Layer::SnapLeft)) {
2107
2108 if (pane) frame = pane->alignToReference(frame); 2152 if (pane) frame = pane->alignToReference(frame);
2109 } else { 2153 } else {
2110 frame = getMainModel()->getStartFrame(); 2154 frame = getMainModel()->getStartFrame();
2111 } 2155 }
2112 } 2156 }
2129 2173
2130 if (m_viewManager->getPlaySelectionMode()) { 2174 if (m_viewManager->getPlaySelectionMode()) {
2131 frame = m_viewManager->constrainFrameToSelection(frame); 2175 frame = m_viewManager->constrainFrameToSelection(frame);
2132 } 2176 }
2133 2177
2178 m_viewManager->setPlaybackFrame(frame);
2179 }
2180
2181 void
2182 MainWindowBase::rewindSimilar()
2183 {
2184 if (!getMainModel()) return;
2185
2186 Layer *layer = getSnapLayer();
2187 if (!layer) { rewind(); return; }
2188
2189 Pane *pane = m_paneStack->getCurrentPane();
2190 size_t sr = getMainModel()->getSampleRate();
2191
2192 int frame = m_viewManager->getPlaybackFrame();
2193
2194 size_t resolution = 0;
2195 if (pane) frame = pane->alignFromReference(frame);
2196 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
2197 frame, resolution, Layer::SnapLeft)) {
2198 if (pane) frame = pane->alignToReference(frame);
2199 } else {
2200 frame = getMainModel()->getStartFrame();
2201 }
2202
2203 if (frame < 0) frame = 0;
2204
2205 if (m_viewManager->getPlaySelectionMode()) {
2206 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
2207 }
2208
2134 m_viewManager->setPlaybackFrame(frame); 2209 m_viewManager->setPlaybackFrame(frame);
2135 } 2210 }
2136 2211
2137 Layer * 2212 Layer *
2138 MainWindowBase::getSnapLayer() const 2213 MainWindowBase::getSnapLayer() const