comparison main/MainWindow.cpp @ 59:1016a8ceceda

* Introduce PlaySpeedRangeMapper for playback speed dial
author Chris Cannam
date Tue, 17 Oct 2006 11:42:14 +0000
parents ca1e3f5657d5
children 06b3c3f437e6
comparison
equal deleted inserted replaced
58:f7cb156508cc 59:1016a8ceceda
39 #include "widgets/ListInputDialog.h" 39 #include "widgets/ListInputDialog.h"
40 #include "widgets/SubdividingMenu.h" 40 #include "widgets/SubdividingMenu.h"
41 #include "audioio/AudioCallbackPlaySource.h" 41 #include "audioio/AudioCallbackPlaySource.h"
42 #include "audioio/AudioCallbackPlayTarget.h" 42 #include "audioio/AudioCallbackPlayTarget.h"
43 #include "audioio/AudioTargetFactory.h" 43 #include "audioio/AudioTargetFactory.h"
44 #include "audioio/PlaySpeedRangeMapper.h"
44 #include "data/fileio/AudioFileReaderFactory.h" 45 #include "data/fileio/AudioFileReaderFactory.h"
45 #include "data/fileio/DataFileReaderFactory.h" 46 #include "data/fileio/DataFileReaderFactory.h"
46 #include "data/fileio/WavFileWriter.h" 47 #include "data/fileio/WavFileWriter.h"
47 #include "data/fileio/CSVFileWriter.h" 48 #include "data/fileio/CSVFileWriter.h"
48 #include "data/fileio/BZipFileDevice.h" 49 #include "data/fileio/BZipFileDevice.h"
175 m_playSpeed->setFixedWidth(24); 176 m_playSpeed->setFixedWidth(24);
176 m_playSpeed->setFixedHeight(24); 177 m_playSpeed->setFixedHeight(24);
177 m_playSpeed->setNotchesVisible(true); 178 m_playSpeed->setNotchesVisible(true);
178 m_playSpeed->setPageStep(10); 179 m_playSpeed->setPageStep(10);
179 m_playSpeed->setToolTip(tr("Playback speed: +0%")); 180 m_playSpeed->setToolTip(tr("Playback speed: +0%"));
181 m_playSpeed->setObjectName(tr("Playback Speed"));
180 m_playSpeed->setDefaultValue(100); 182 m_playSpeed->setDefaultValue(100);
183 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
181 connect(m_playSpeed, SIGNAL(valueChanged(int)), 184 connect(m_playSpeed, SIGNAL(valueChanged(int)),
182 this, SLOT(playSpeedChanged(int))); 185 this, SLOT(playSpeedChanged(int)));
183 186
184 m_playSharpen = new QPushButton(frame); 187 m_playSharpen = new QPushButton(frame);
185 m_playSharpen->setToolTip(tr("Sharpen percussive transients")); 188 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
3077 } 3080 }
3078 } 3081 }
3079 } 3082 }
3080 3083
3081 void 3084 void
3082 MainWindow::playSpeedChanged(int speed) 3085 MainWindow::playSpeedChanged(int position)
3083 { 3086 {
3084 bool slow = false; 3087 PlaySpeedRangeMapper mapper(0, 200);
3085 bool something = false; 3088 float factor = mapper.getFactorForPosition(position);
3086 float factor; 3089 float percent = mapper.getValueForPosition(position);
3087 3090
3088 if (speed < 100) { 3091 // std::cerr << "speed = " << position << " factor = " << factor << std::endl;
3089 slow = true; 3092
3090 speed = 100 - speed; 3093 bool slow = (position < 100);
3091 } else { 3094 bool something = (position != 100);
3092 speed = speed - 100; 3095
3093 } 3096 int pc = lrintf(percent);
3094
3095 // speed is 0 -> 100
3096
3097 if (speed == 0) {
3098 factor = 1.0;
3099 } else {
3100 factor = speed;
3101 factor = 1.0 + (factor * factor) / 1000.f;
3102 something = true;
3103 }
3104
3105 int pc = lrintf((factor - 1.0) * 100);
3106
3107 if (!slow) factor = 1.0 / factor;
3108
3109 std::cerr << "speed = " << speed << " factor = " << factor << std::endl;
3110 3097
3111 m_playSpeed->setToolTip(tr("Playback speed: %1%2%") 3098 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
3112 .arg(!slow ? "+" : "-") 3099 .arg(!slow ? "+" : "-")
3113 .arg(pc)); 3100 .arg(pc));
3114 3101