comparison src/Analyser.cpp @ 168:c5e4eaeb9a27

Add ability to delete selection of pitch track
author Chris Cannam
date Tue, 04 Feb 2014 13:55:26 +0000
parents 6b6906017536
children e33f9d052503
comparison
equal deleted inserted replaced
167:6b6906017536 168:c5e4eaeb9a27
331 { 331 {
332 if (m_reAnalysisCandidates.empty()) return; 332 if (m_reAnalysisCandidates.empty()) return;
333 333
334 if (up) { 334 if (up) {
335 m_currentCandidate = m_currentCandidate + 1; 335 m_currentCandidate = m_currentCandidate + 1;
336 if (m_currentCandidate >= m_reAnalysisCandidates.size()) { 336 if (m_currentCandidate >= (int)m_reAnalysisCandidates.size()) {
337 m_currentCandidate = 0; 337 m_currentCandidate = 0;
338 } 338 }
339 } else { 339 } else {
340 m_currentCandidate = m_currentCandidate - 1; 340 m_currentCandidate = m_currentCandidate - 1;
341 if (m_currentCandidate < 0) { 341 if (m_currentCandidate < 0) {
342 m_currentCandidate = m_reAnalysisCandidates.size() - 1; 342 m_currentCandidate = (int)m_reAnalysisCandidates.size() - 1;
343 } 343 }
344 } 344 }
345 345
346 Layer *pitchTrack = m_layers[PitchTrack]; 346 Layer *pitchTrack = m_layers[PitchTrack];
347 if (!pitchTrack) return; 347 if (!pitchTrack) return;
348
349 CommandHistory::getInstance()->startCompoundOperation
350 (tr("Switch Pitch Candidate"), true);
351 348
352 Clipboard clip; 349 Clipboard clip;
353 pitchTrack->deleteSelection(sel); 350 pitchTrack->deleteSelection(sel);
354 m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip); 351 m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip);
355 pitchTrack->paste(m_pane, clip, 0, false); 352 pitchTrack->paste(m_pane, clip, 0, false);
356 353
357 CommandHistory::getInstance()->endCompoundOperation();
358
359 // raise the pitch track, then notes on top (if present) 354 // raise the pitch track, then notes on top (if present)
360 m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]); 355 m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]);
361 if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) { 356 if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) {
362 m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]); 357 m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]);
363 } 358 }
364 } 359 }
365 360
366 void 361 void
362 Analyser::shiftOctave(Selection sel, bool up)
363 {
364 float factor = (up ? 2.f : 0.5f);
365
366 vector<Layer *> actOn;
367
368 Layer *pitchTrack = m_layers[PitchTrack];
369 if (pitchTrack) actOn.push_back(pitchTrack);
370
371 foreach (Layer *c, m_reAnalysisCandidates) {
372 actOn.push_back(c);
373 }
374
375 foreach (Layer *layer, actOn) {
376
377 Clipboard clip;
378 layer->copy(m_pane, sel, clip);
379 layer->deleteSelection(sel);
380
381 Clipboard shifted;
382 foreach (Clipboard::Point p, clip.getPoints()) {
383 if (p.haveValue()) {
384 Clipboard::Point sp = p.withValue(p.getValue() * factor);
385 shifted.addPoint(sp);
386 } else {
387 shifted.addPoint(p);
388 }
389 }
390
391 layer->paste(m_pane, shifted, 0, false);
392 }
393 }
394
395 void
396 Analyser::clearPitches(Selection sel)
397 {
398 Layer *pitchTrack = m_layers[PitchTrack];
399 if (!pitchTrack) return;
400
401 pitchTrack->deleteSelection(sel);
402 }
403
404 void
367 Analyser::clearReAnalysis() 405 Analyser::clearReAnalysis()
368 { 406 {
369 foreach (Layer *layer, m_reAnalysisCandidates) { 407 foreach (Layer *layer, m_reAnalysisCandidates) {
370 m_pane->removeLayer(layer); 408 m_document->removeLayerFromView(m_pane, layer);
371 m_document->deleteLayer(layer); // also releases its model 409 m_document->deleteLayer(layer); // also releases its model
372 } 410 }
373 m_reAnalysisCandidates.clear(); 411 m_reAnalysisCandidates.clear();
374 m_reAnalysingSelection = Selection(); 412 m_reAnalysingSelection = Selection();
375 m_currentCandidate = -1; 413 m_currentCandidate = -1;