Mercurial > hg > svcore
comparison data/fileio/CSVFileReader.cpp @ 1649:1cc9a0d4b1b6 single-point
Update RegionModel following NoteModel, er, model. They have quite a bit in common that we should now pull out some of
author | Chris Cannam |
---|---|
date | Fri, 15 Mar 2019 14:23:50 +0000 |
parents | 513192aa9b03 |
children | 7a56bb85030f |
comparison
equal
deleted
inserted
replaced
1648:86bbccb79c9b | 1649:1cc9a0d4b1b6 |
---|---|
445 SparseTimeValueModel::Point point(frameNo, value, label); | 445 SparseTimeValueModel::Point point(frameNo, value, label); |
446 model2->addPoint(point); | 446 model2->addPoint(point); |
447 | 447 |
448 } else if (modelType == CSVFormat::TwoDimensionalModelWithDuration) { | 448 } else if (modelType == CSVFormat::TwoDimensionalModelWithDuration) { |
449 | 449 |
450 RegionModel::Point point(frameNo, value, duration, label); | 450 Event region(frameNo, value, duration, label); |
451 model2a->addPoint(point); | 451 model2a->add(region); |
452 | 452 |
453 } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndPitch) { | 453 } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndPitch) { |
454 | 454 |
455 float level = ((value >= 0.f && value <= 1.f) ? value : 1.f); | 455 float level = ((value >= 0.f && value <= 1.f) ? value : 1.f); |
456 Event note(frameNo, pitch, duration, level, label); | 456 Event note(frameNo, pitch, duration, level, label); |
579 SVCERR << "label -> " << j->first << ", value " << v << endl; | 579 SVCERR << "label -> " << j->first << ", value " << v << endl; |
580 v = v + 1.f; | 580 v = v + 1.f; |
581 } | 581 } |
582 } | 582 } |
583 | 583 |
584 map<RegionModel::Point, RegionModel::Point, | 584 map<Event, Event> eventMap; |
585 RegionModel::Point::Comparator> pointMap; | 585 |
586 for (RegionModel::PointList::const_iterator i = | 586 EventVector allEvents = model2a->getAllEvents(); |
587 model2a->getPoints().begin(); | 587 for (const Event &e: allEvents) { |
588 i != model2a->getPoints().end(); ++i) { | 588 int count = labelCountMap[e.getLabel()]; |
589 RegionModel::Point p(*i); | 589 v = countLabelValueMap[count][e.getLabel()]; |
590 int count = labelCountMap[p.label]; | 590 // SVCERR << "mapping from label \"" << p.label |
591 v = countLabelValueMap[count][p.label]; | 591 // << "\" (count " << count |
592 // SVCERR << "mapping from label \"" << p.label << "\" (count " << count << ") to value " << v << endl; | 592 // << ") to value " << v << endl; |
593 RegionModel::Point pp(p.frame, v, p.duration, p.label); | 593 eventMap[e] = Event(e.getFrame(), v, |
594 pointMap[p] = pp; | 594 e.getDuration(), e.getLabel()); |
595 } | 595 } |
596 | 596 |
597 for (map<RegionModel::Point, RegionModel::Point>::iterator i = | 597 for (const auto &i: eventMap) { |
598 pointMap.begin(); i != pointMap.end(); ++i) { | |
599 // There could be duplicate regions; if so replace | 598 // There could be duplicate regions; if so replace |
600 // them all -- but we need to check we're not | 599 // them all -- but we need to check we're not |
601 // replacing a region by itself (or else this will | 600 // replacing a region by itself (or else this will |
602 // never terminate) | 601 // never terminate) |
603 if (i->first.value == i->second.value) { | 602 if (i.first.getValue() == i.second.getValue()) { |
604 continue; | 603 continue; |
605 } | 604 } |
606 while (model2a->containsPoint(i->first)) { | 605 while (model2a->containsEvent(i.first)) { |
607 model2a->deletePoint(i->first); | 606 model2a->remove(i.first); |
608 model2a->addPoint(i->second); | 607 model2a->add(i.second); |
609 } | 608 } |
610 } | 609 } |
611 } | 610 } |
612 } | 611 } |
613 | 612 |