! @excsafety{Strong} -- For state of current project's tracks */
| 634 | |
| 635 | /*! @excsafety{Strong} -- For state of current project's tracks */ |
| 636 | void ProjectAudioManager::OnRecord(bool altAppearance) |
| 637 | { |
| 638 | bool bPreferNewTrack; |
| 639 | gPrefs->Read("/GUI/PreferNewTrackRecord", &bPreferNewTrack, false); |
| 640 | const bool appendRecord = (altAppearance == bPreferNewTrack); |
| 641 | |
| 642 | // Code from CommandHandler start... |
| 643 | AudacityProject *p = &mProject; |
| 644 | |
| 645 | if (p) { |
| 646 | const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion; |
| 647 | double t0 = selectedRegion.t0(); |
| 648 | double t1 = selectedRegion.t1(); |
| 649 | // When no time selection, recording duration is 'unlimited'. |
| 650 | if (t1 == t0) |
| 651 | t1 = DBL_MAX; |
| 652 | |
| 653 | auto options = ProjectAudioIO::GetDefaultOptions(*p); |
| 654 | WritableSampleTrackArray existingTracks; |
| 655 | |
| 656 | // Checking the selected tracks: counting them and |
| 657 | // making sure they all have the same rate |
| 658 | const auto selectedTracks{ GetPropertiesOfSelected(*p) }; |
| 659 | const int rateOfSelected{ selectedTracks.rateOfSelected }; |
| 660 | const bool anySelected{ selectedTracks.anySelected }; |
| 661 | const bool allSameRate{ selectedTracks.allSameRate }; |
| 662 | |
| 663 | if (!allSameRate) { |
| 664 | AudacityMessageBox(XO("The tracks selected " |
| 665 | "for recording must all have the same sampling rate"), |
| 666 | XO("Mismatched Sampling Rates"), |
| 667 | wxICON_ERROR | wxCENTRE); |
| 668 | |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | if (appendRecord) { |
| 673 | // Try to find wave tracks to record into. (If any are selected, |
| 674 | // try to choose only from them; else if wave tracks exist, may record into any.) |
| 675 | existingTracks = ChooseExistingRecordingTracks(*p, true, rateOfSelected); |
| 676 | if (!existingTracks.empty()) { |
| 677 | t0 = std::max(t0, |
| 678 | TrackList::Get(*p).Selected<const WaveTrack>() |
| 679 | .max(&Track::GetEndTime)); |
| 680 | options.rate = rateOfSelected; |
| 681 | } |
| 682 | else { |
| 683 | if (anySelected && rateOfSelected != options.rate) { |
| 684 | AudacityMessageBox(XO( |
| 685 | "Too few tracks are selected for recording at this sample rate.\n" |
| 686 | "(Audacity requires two channels at the same sample rate for\n" |
| 687 | "each stereo track)"), |
| 688 | XO("Too Few Compatible Tracks Selected"), |
| 689 | wxICON_ERROR | wxCENTRE); |
| 690 | |
| 691 | return; |
| 692 | } |
| 693 |
no test coverage detected