comparison src/MainWindow.cpp @ 399:ffd1a89a68fa cxx11-types

Build fixes etc
author Chris Cannam
date Wed, 11 Mar 2015 11:54:29 +0000
parents c66ec7f40acb
children a0eedd10dee3
comparison
equal deleted inserted replaced
352:7178bb4dcdfb 399:ffd1a89a68fa
86 #include <errno.h> 86 #include <errno.h>
87 87
88 using std::vector; 88 using std::vector;
89 89
90 90
91 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) : 91 MainWindow::MainWindow(bool withAudioOutput) :
92 MainWindowBase(withAudioOutput, false), 92 MainWindowBase(withAudioOutput, false),
93 m_overview(0), 93 m_overview(0),
94 m_mainMenusCreated(false), 94 m_mainMenusCreated(false),
95 m_playbackMenu(0), 95 m_playbackMenu(0),
96 m_recentFilesMenu(0), 96 m_recentFilesMenu(0),
180 // We have a pane stack: it comes with the territory. However, we 180 // We have a pane stack: it comes with the territory. However, we
181 // have a fixed and known number of panes in it -- it isn't 181 // have a fixed and known number of panes in it -- it isn't
182 // variable 182 // variable
183 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks); 183 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
184 m_paneStack->setShowPaneAccessories(false); 184 m_paneStack->setShowPaneAccessories(false);
185 connect(m_paneStack, SIGNAL(doubleClickSelectInvoked(size_t)), 185 connect(m_paneStack, SIGNAL(doubleClickSelectInvoked(sv_frame_t)),
186 this, SLOT(doubleClickSelectInvoked(size_t))); 186 this, SLOT(doubleClickSelectInvoked(sv_frame_t)));
187 scroll->setWidget(m_paneStack); 187 scroll->setWidget(m_paneStack);
188 188
189 m_overview = new Overview(frame); 189 m_overview = new Overview(frame);
190 m_overview->setViewManager(m_viewManager); 190 m_overview->setViewManager(m_viewManager);
191 m_overview->setFixedHeight(40); 191 m_overview->setFixedHeight(40);
1236 1236
1237 1237
1238 void 1238 void
1239 MainWindow::moveByOneNote(bool right, bool doSelect) 1239 MainWindow::moveByOneNote(bool right, bool doSelect)
1240 { 1240 {
1241 int frame = m_viewManager->getPlaybackFrame(); 1241 sv_frame_t frame = m_viewManager->getPlaybackFrame();
1242 cerr << "MainWindow::moveByOneNote startframe: " << frame << endl; 1242 cerr << "MainWindow::moveByOneNote startframe: " << frame << endl;
1243 1243
1244 Pane *p = m_analyser->getPane();
1245
1246 bool isAtSelectionBoundary = false; 1244 bool isAtSelectionBoundary = false;
1247 MultiSelection::SelectionList selections = m_viewManager->getSelections(); 1245 MultiSelection::SelectionList selections = m_viewManager->getSelections();
1248 if (!selections.empty()) { 1246 if (!selections.empty()) {
1249 Selection sel = *selections.begin(); 1247 Selection sel = *selections.begin();
1250 isAtSelectionBoundary = (frame == sel.getStartFrame()) || (frame == sel.getEndFrame()); 1248 isAtSelectionBoundary = (frame == sel.getStartFrame()) || (frame == sel.getEndFrame());
1261 1259
1262 FlexiNoteModel::PointList points = model->getPoints(); 1260 FlexiNoteModel::PointList points = model->getPoints();
1263 if (points.empty()) return; 1261 if (points.empty()) return;
1264 1262
1265 FlexiNoteModel::PointList::iterator i = points.begin(); 1263 FlexiNoteModel::PointList::iterator i = points.begin();
1266 std::set<int> snapFrames; 1264 std::set<sv_frame_t> snapFrames;
1267 snapFrames.insert(0); 1265 snapFrames.insert(0);
1268 while (i != points.end()) { 1266 while (i != points.end()) {
1269 snapFrames.insert(i->frame); 1267 snapFrames.insert(i->frame);
1270 snapFrames.insert(i->frame + i->duration + 1); 1268 snapFrames.insert(i->frame + i->duration + 1);
1271 ++i; 1269 ++i;
1272 } 1270 }
1273 std::set<int>::iterator i2; 1271 std::set<sv_frame_t>::iterator i2;
1274 if (snapFrames.find(frame) == snapFrames.end()) 1272 if (snapFrames.find(frame) == snapFrames.end()) {
1275 {
1276 // we're not on an existing snap point, so go to previous 1273 // we're not on an existing snap point, so go to previous
1277 snapFrames.insert(frame); 1274 snapFrames.insert(frame);
1278 } 1275 }
1279 i2 = snapFrames.find(frame); 1276 i2 = snapFrames.find(frame);
1280 if (right) 1277 if (right) {
1281 {
1282 i2++; 1278 i2++;
1283 if (i2 == snapFrames.end()) i2--; 1279 if (i2 == snapFrames.end()) i2--;
1284 } else { 1280 } else {
1285 if (i2 != snapFrames.begin()) i2--; 1281 if (i2 != snapFrames.begin()) i2--;
1286 } 1282 }
1343 (haveCurrentPane && 1339 (haveCurrentPane &&
1344 (currentLayer != 0)); 1340 (currentLayer != 0));
1345 bool haveSelection = 1341 bool haveSelection =
1346 (m_viewManager && 1342 (m_viewManager &&
1347 !m_viewManager->getSelections().empty()); 1343 !m_viewManager->getSelections().empty());
1348 bool haveCurrentEditableLayer =
1349 (haveCurrentLayer &&
1350 currentLayer->isLayerEditable());
1351 bool haveCurrentTimeInstantsLayer = 1344 bool haveCurrentTimeInstantsLayer =
1352 (haveCurrentLayer && 1345 (haveCurrentLayer &&
1353 qobject_cast<TimeInstantLayer *>(currentLayer)); 1346 qobject_cast<TimeInstantLayer *>(currentLayer));
1354 bool haveCurrentTimeValueLayer = 1347 bool haveCurrentTimeValueLayer =
1355 (haveCurrentLayer && 1348 (haveCurrentLayer &&
1356 qobject_cast<TimeValueLayer *>(currentLayer)); 1349 qobject_cast<TimeValueLayer *>(currentLayer));
1357 bool pitchCandidatesVisible = 1350 bool pitchCandidatesVisible =
1358 m_analyser->arePitchCandidatesShown(); 1351 m_analyser->arePitchCandidatesShown();
1359 bool haveHigher =
1360 m_analyser->haveHigherPitchCandidate();
1361 bool haveLower =
1362 m_analyser->haveLowerPitchCandidate();
1363 1352
1364 emit canChangePlaybackSpeed(true); 1353 emit canChangePlaybackSpeed(true);
1365 int v = m_playSpeed->value(); 1354 int v = m_playSpeed->value();
1366 emit canSpeedUpPlayback(v < m_playSpeed->maximum()); 1355 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
1367 emit canSlowDownPlayback(v > m_playSpeed->minimum()); 1356 emit canSlowDownPlayback(v > m_playSpeed->minimum());
1520 } 1509 }
1521 1510
1522 void 1511 void
1523 MainWindow::editDisplayExtents() 1512 MainWindow::editDisplayExtents()
1524 { 1513 {
1525 float min, max; 1514 double min, max;
1526 float vmin = 0; 1515 double vmin = 0;
1527 float vmax = getMainModel()->getSampleRate() /2; 1516 double vmax = getMainModel()->getSampleRate() /2;
1528 1517
1529 if (!m_analyser->getDisplayFrequencyExtents(min, max)) { 1518 if (!m_analyser->getDisplayFrequencyExtents(min, max)) {
1530 //!!! 1519 //!!!
1531 return; 1520 return;
1532 } 1521 }
1533 1522
1534 RangeInputDialog dialog(tr("Set frequency range"), 1523 RangeInputDialog dialog(tr("Set frequency range"),
1535 tr("Enter new frequency range, from %1 to %2 Hz.\nThese values will be rounded to the nearest spectrogram bin.") 1524 tr("Enter new frequency range, from %1 to %2 Hz.\nThese values will be rounded to the nearest spectrogram bin.")
1536 .arg(vmin).arg(vmax), 1525 .arg(vmin).arg(vmax),
1537 "Hz", vmin, vmax, this); 1526 "Hz", float(vmin), float(vmax), this);
1538 dialog.setRange(min, max); 1527 dialog.setRange(float(min), float(max));
1539 1528
1540 if (dialog.exec() == QDialog::Accepted) { 1529 if (dialog.exec() == QDialog::Accepted) {
1541 dialog.getRange(min, max); 1530 float fmin, fmax;
1531 dialog.getRange(fmin, fmax);
1532 min = fmin;
1533 max = fmax;
1542 if (min > max) { 1534 if (min > max) {
1543 float tmp = max; 1535 double tmp = max;
1544 max = min; 1536 max = min;
1545 min = tmp; 1537 min = tmp;
1546 } 1538 }
1547 m_analyser->setDisplayFrequencyExtents(min, max); 1539 m_analyser->setDisplayFrequencyExtents(min, max);
1548 } 1540 }
2267 emit activity(tr("Export layer to \"%1\"").arg(path)); 2259 emit activity(tr("Export layer to \"%1\"").arg(path));
2268 } 2260 }
2269 } 2261 }
2270 2262
2271 void 2263 void
2272 MainWindow::doubleClickSelectInvoked(size_t frame) 2264 MainWindow::doubleClickSelectInvoked(sv_frame_t frame)
2273 { 2265 {
2274 size_t f0, f1; 2266 sv_frame_t f0, f1;
2275 m_analyser->getEnclosingSelectionScope(frame, f0, f1); 2267 m_analyser->getEnclosingSelectionScope(frame, f0, f1);
2276 2268
2277 cerr << "MainWindow::doubleClickSelectInvoked(" << frame << "): [" << f0 << "," << f1 << "]" << endl; 2269 cerr << "MainWindow::doubleClickSelectInvoked(" << frame << "): [" << f0 << "," << f1 << "]" << endl;
2278 2270
2279 Selection sel(f0, f1); 2271 Selection sel(f0, f1);
2354 if (!spectrogram) { 2346 if (!spectrogram) {
2355 cerr << "MainWindow::regionOutlined: no spectrogram layer, ignoring" << endl; 2347 cerr << "MainWindow::regionOutlined: no spectrogram layer, ignoring" << endl;
2356 return; 2348 return;
2357 } 2349 }
2358 2350
2359 int f0 = pane->getFrameForX(r.x()); 2351 sv_frame_t f0 = pane->getFrameForX(r.x());
2360 int f1 = pane->getFrameForX(r.x() + r.width()); 2352 sv_frame_t f1 = pane->getFrameForX(r.x() + r.width());
2361 2353
2362 float v0 = spectrogram->getFrequencyForY(pane, r.y() + r.height()); 2354 double v0 = spectrogram->getFrequencyForY(pane, r.y() + r.height());
2363 float v1 = spectrogram->getFrequencyForY(pane, r.y()); 2355 double v1 = spectrogram->getFrequencyForY(pane, r.y());
2364 2356
2365 cerr << "MainWindow::regionOutlined: frame " << f0 << " -> " << f1 2357 cerr << "MainWindow::regionOutlined: frame " << f0 << " -> " << f1
2366 << ", frequency " << v0 << " -> " << v1 << endl; 2358 << ", frequency " << v0 << " -> " << v1 << endl;
2367 2359
2368 m_pendingConstraint = Analyser::FrequencyRange(v0, v1); 2360 m_pendingConstraint = Analyser::FrequencyRange(v0, v1);
2569 2561
2570 CommandHistory::getInstance()->startCompoundOperation 2562 CommandHistory::getInstance()->startCompoundOperation
2571 (tr("Form Note from Selection"), true); 2563 (tr("Form Note from Selection"), true);
2572 for (MultiSelection::SelectionList::iterator k = selections.begin(); 2564 for (MultiSelection::SelectionList::iterator k = selections.begin();
2573 k != selections.end(); ++k) { 2565 k != selections.end(); ++k) {
2574 if (!model->getNotes(k->getStartFrame(), k->getEndFrame()).empty()) { 2566 if (!model->getNotesWithin(k->getStartFrame(), k->getEndFrame()).empty()) {
2575 layer->splitNotesAt(m_analyser->getPane(), k->getStartFrame()); 2567 layer->splitNotesAt(m_analyser->getPane(), k->getStartFrame());
2576 layer->splitNotesAt(m_analyser->getPane(), k->getEndFrame()); 2568 layer->splitNotesAt(m_analyser->getPane(), k->getEndFrame());
2577 layer->mergeNotes(m_analyser->getPane(), *k, false); 2569 layer->mergeNotes(m_analyser->getPane(), *k, false);
2578 } else { 2570 } else {
2579 layer->addNoteOn(k->getStartFrame(), 100, 100); 2571 layer->addNoteOn(k->getStartFrame(), 100, 100);
2589 void 2581 void
2590 MainWindow::playSpeedChanged(int position) 2582 MainWindow::playSpeedChanged(int position)
2591 { 2583 {
2592 PlaySpeedRangeMapper mapper(0, 200); 2584 PlaySpeedRangeMapper mapper(0, 200);
2593 2585
2594 float percent = m_playSpeed->mappedValue(); 2586 double percent = m_playSpeed->mappedValue();
2595 float factor = mapper.getFactorForValue(percent); 2587 double factor = mapper.getFactorForValue(percent);
2596 2588
2597 cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << endl; 2589 cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << endl;
2598 2590
2599 bool something = (position != 100); 2591 bool something = (position != 100);
2600 2592
2601 int pc = lrintf(percent); 2593 int pc = int(lrint(percent));
2602 2594
2603 if (!something) { 2595 if (!something) {
2604 contextHelpChanged(tr("Playback speed: Normal")); 2596 contextHelpChanged(tr("Playback speed: Normal"));
2605 } else { 2597 } else {
2606 contextHelpChanged(tr("Playback speed: %1%2%") 2598 contextHelpChanged(tr("Playback speed: %1%2%")
2662 } 2654 }
2663 2655
2664 void 2656 void
2665 MainWindow::audioGainChanged(int position) 2657 MainWindow::audioGainChanged(int position)
2666 { 2658 {
2667 float level = m_gainAudio->mappedValue(); 2659 double level = m_gainAudio->mappedValue();
2668 float gain = powf(10, level / 20.0); 2660 double gain = pow(10, level / 20.0);
2669 2661
2670 cerr << "gain = " << gain << " (" << position << " dB)" << endl; 2662 cerr << "gain = " << gain << " (" << position << " dB)" << endl;
2671 2663
2672 contextHelpChanged(tr("Audio Gain: %1 dB").arg(position)); 2664 contextHelpChanged(tr("Audio Gain: %1 dB").arg(position));
2673 2665
2674 m_analyser->setGain(Analyser::Audio, gain); 2666 m_analyser->setGain(Analyser::Audio, float(gain));
2675 2667
2676 updateMenuStates(); 2668 updateMenuStates();
2677 } 2669 }
2678 2670
2679 void 2671 void
2701 } 2693 }
2702 2694
2703 void 2695 void
2704 MainWindow::pitchGainChanged(int position) 2696 MainWindow::pitchGainChanged(int position)
2705 { 2697 {
2706 float level = m_gainPitch->mappedValue(); 2698 double level = m_gainPitch->mappedValue();
2707 float gain = powf(10, level / 20.0); 2699 double gain = pow(10, level / 20.0);
2708 2700
2709 cerr << "gain = " << gain << " (" << position << " dB)" << endl; 2701 cerr << "gain = " << gain << " (" << position << " dB)" << endl;
2710 2702
2711 contextHelpChanged(tr("Pitch Gain: %1 dB").arg(position)); 2703 contextHelpChanged(tr("Pitch Gain: %1 dB").arg(position));
2712 2704
2713 m_analyser->setGain(Analyser::PitchTrack, gain); 2705 m_analyser->setGain(Analyser::PitchTrack, float(gain));
2714 2706
2715 updateMenuStates(); 2707 updateMenuStates();
2716 } 2708 }
2717 2709
2718 void 2710 void
2740 } 2732 }
2741 2733
2742 void 2734 void
2743 MainWindow::notesGainChanged(int position) 2735 MainWindow::notesGainChanged(int position)
2744 { 2736 {
2745 float level = m_gainNotes->mappedValue(); 2737 double level = m_gainNotes->mappedValue();
2746 float gain = powf(10, level / 20.0); 2738 double gain = pow(10, level / 20.0);
2747 2739
2748 cerr << "gain = " << gain << " (" << position << " dB)" << endl; 2740 cerr << "gain = " << gain << " (" << position << " dB)" << endl;
2749 2741
2750 contextHelpChanged(tr("Notes Gain: %1 dB").arg(position)); 2742 contextHelpChanged(tr("Notes Gain: %1 dB").arg(position));
2751 2743
2752 m_analyser->setGain(Analyser::Notes, gain); 2744 m_analyser->setGain(Analyser::Notes, float(gain));
2753 2745
2754 updateMenuStates(); 2746 updateMenuStates();
2755 } 2747 }
2756 2748
2757 void 2749 void
2779 } 2771 }
2780 2772
2781 void 2773 void
2782 MainWindow::audioPanChanged(int position) 2774 MainWindow::audioPanChanged(int position)
2783 { 2775 {
2784 float level = m_panAudio->mappedValue(); 2776 double level = m_panAudio->mappedValue();
2785 float pan = level/100.f; 2777 double pan = level/100.0;
2786 2778
2787 cerr << "pan = " << pan << " (" << position << ")" << endl; 2779 cerr << "pan = " << pan << " (" << position << ")" << endl;
2788 2780
2789 contextHelpChanged(tr("Audio Pan: %1").arg(position)); 2781 contextHelpChanged(tr("Audio Pan: %1").arg(position));
2790 2782
2791 m_analyser->setPan(Analyser::Audio, pan); 2783 m_analyser->setPan(Analyser::Audio, float(pan));
2792 2784
2793 updateMenuStates(); 2785 updateMenuStates();
2794 } 2786 }
2795 2787
2796 void 2788 void
2818 } 2810 }
2819 2811
2820 void 2812 void
2821 MainWindow::pitchPanChanged(int position) 2813 MainWindow::pitchPanChanged(int position)
2822 { 2814 {
2823 float level = m_panPitch->mappedValue(); 2815 double level = m_panPitch->mappedValue();
2824 float pan = level/100.f; 2816 double pan = level/100.0;
2825 2817
2826 cerr << "pan = " << pan << " (" << position << ")" << endl; 2818 cerr << "pan = " << pan << " (" << position << ")" << endl;
2827 2819
2828 contextHelpChanged(tr("Pitch Pan: %1").arg(position)); 2820 contextHelpChanged(tr("Pitch Pan: %1").arg(position));
2829 2821
2830 m_analyser->setPan(Analyser::PitchTrack, pan); 2822 m_analyser->setPan(Analyser::PitchTrack, float(pan));
2831 2823
2832 updateMenuStates(); 2824 updateMenuStates();
2833 } 2825 }
2834 2826
2835 void 2827 void
2857 } 2849 }
2858 2850
2859 void 2851 void
2860 MainWindow::notesPanChanged(int position) 2852 MainWindow::notesPanChanged(int position)
2861 { 2853 {
2862 float level = m_panNotes->mappedValue(); 2854 double level = m_panNotes->mappedValue();
2863 float pan = level/100.f; 2855 double pan = level/100.0;
2864 2856
2865 cerr << "pan = " << pan << " (" << position << ")" << endl; 2857 cerr << "pan = " << pan << " (" << position << ")" << endl;
2866 2858
2867 contextHelpChanged(tr("Notes Pan: %1").arg(position)); 2859 contextHelpChanged(tr("Notes Pan: %1").arg(position));
2868 2860
2869 m_analyser->setPan(Analyser::Notes, pan); 2861 m_analyser->setPan(Analyser::Notes, float(pan));
2870 2862
2871 updateMenuStates(); 2863 updateMenuStates();
2872 } 2864 }
2873 2865
2874 void 2866 void
2959 m_fader->setPeakLeft(left); 2951 m_fader->setPeakLeft(left);
2960 m_fader->setPeakRight(right); 2952 m_fader->setPeakRight(right);
2961 } 2953 }
2962 2954
2963 void 2955 void
2964 MainWindow::sampleRateMismatch(size_t requested, size_t actual, 2956 MainWindow::sampleRateMismatch(sv_samplerate_t ,
2965 bool willResample) 2957 sv_samplerate_t ,
2958 bool )
2966 { 2959 {
2967 updateDescriptionLabel(); 2960 updateDescriptionLabel();
2968 } 2961 }
2969 2962
2970 void 2963 void
3130 QMessageBox::Ok); 3123 QMessageBox::Ok);
3131 } 3124 }
3132 } 3125 }
3133 3126
3134 void 3127 void
3135 MainWindow::modelGenerationWarning(QString transformName, QString message) 3128 MainWindow::modelGenerationWarning(QString /* transformName */, QString message)
3136 { 3129 {
3137 QMessageBox::warning 3130 QMessageBox::warning
3138 (this, tr("Warning"), message, QMessageBox::Ok); 3131 (this, tr("Warning"), message, QMessageBox::Ok);
3139 } 3132 }
3140 3133
3141 void 3134 void
3142 MainWindow::modelRegenerationFailed(QString layerName, 3135 MainWindow::modelRegenerationFailed(QString layerName,
3143 QString transformName, QString message) 3136 QString transformName,
3137 QString message)
3144 { 3138 {
3145 if (message != "") { 3139 if (message != "") {
3146 3140
3147 QMessageBox::warning 3141 QMessageBox::warning
3148 (this, 3142 (this,
3160 } 3154 }
3161 } 3155 }
3162 3156
3163 void 3157 void
3164 MainWindow::modelRegenerationWarning(QString layerName, 3158 MainWindow::modelRegenerationWarning(QString layerName,
3165 QString transformName, QString message) 3159 QString /* transformName */,
3160 QString message)
3166 { 3161 {
3167 QMessageBox::warning 3162 QMessageBox::warning
3168 (this, tr("Warning"), tr("<b>Warning when regenerating layer</b><p>When regenerating the derived layer \"%1\" using new data model as input:<p>%2").arg(layerName).arg(message), QMessageBox::Ok); 3163 (this, tr("Warning"), tr("<b>Warning when regenerating layer</b><p>When regenerating the derived layer \"%1\" using new data model as input:<p>%2").arg(layerName).arg(message), QMessageBox::Ok);
3169 } 3164 }
3170 3165
3186 m_paneStack->setCurrentPane(pane); 3181 m_paneStack->setCurrentPane(pane);
3187 m_rightButtonMenu->popup(position); 3182 m_rightButtonMenu->popup(position);
3188 } 3183 }
3189 3184
3190 void 3185 void
3191 MainWindow::handleOSCMessage(const OSCMessage &message) 3186 MainWindow::handleOSCMessage(const OSCMessage &)
3192 { 3187 {
3193 cerr << "MainWindow::handleOSCMessage: Not implemented" << endl; 3188 cerr << "MainWindow::handleOSCMessage: Not implemented" << endl;
3194 } 3189 }
3195 3190
3196 void 3191 void