barelymusician/engine/sequence_test.cpp
// Tests that sequence processes multiple notes as expected.
Tests that sequence processes multiple notes as expected.
Tests that sequence processes multiple notes as expected .
TEST(SequenceTest, ProcessMultipleNotes) {
  Conductor conductor;
  Transport transport;
  transport.SetTempo(60.0);
  Sequence sequence(conductor, transport);
  EXPECT_THAT(sequence.GetInstrument(), IsNull());
  std::vector<std::pair<double, double>> note_ons;
  std::vector<std::pair<double, double>> note_offs;
  Instrument instrument(Instrument::Definition({}), 1);
  instrument.SetNoteOnCallback(
      [&](double pitch, double intensity, double timestamp) {
        EXPECT_DOUBLE_EQ(intensity, 1.0);
        note_ons.emplace_back(pitch, timestamp);
      });
  instrument.SetNoteOffCallback([&](double pitch, double timestamp) {
    note_offs.emplace_back(pitch, timestamp);
  });
  sequence.SetInstrument(&instrument);
  EXPECT_THAT(sequence.GetInstrument(), &instrument);
  for (int i = 0; i < 4; ++i) {
    EXPECT_TRUE(sequence.CreateNote(
        static_cast<Id>(i + 1),
        Note::Definition(1.0, Note::PitchDefinition::AbsolutePitch(
                                  static_cast<double>(i + 1))),
        static_cast<double>(i)));
    EXPECT_THAT(sequence.GetNotePosition(static_cast<Id>(i + 1)),
                AllOf(NotNull(), Pointee(static_cast<double>(i))));
  }
  sequence.Process(0.0, 4.0);
  EXPECT_THAT(note_ons, ElementsAre(Pair(1.0, 0.0), Pair(2.0, 1.0),
                                    Pair(3.0, 2.0), Pair(4.0, 3.0)));
  EXPECT_THAT(note_offs,
              ElementsAre(Pair(1.0, 1.0), Pair(2.0, 2.0), Pair(3.0, 3.0)));
  note_ons.clear();
  note_offs.clear();
  sequence.Stop();
  EXPECT_TRUE(note_ons.empty());
  EXPECT_THAT(note_offs, ElementsAre(Pair(4.0, 0.0)));
  note_ons.clear();
  note_offs.clear();
  sequence.SetBeginOffset(1.0);
  EXPECT_DOUBLE_EQ(sequence.GetBeginOffset(), 1.0);
  sequence.SetLooping(true);
  EXPECT_TRUE(sequence.IsLooping());
  sequence.SetLoopBeginOffset(2.0);
  EXPECT_DOUBLE_EQ(sequence.GetLoopBeginOffset(), 2.0);
  sequence.SetLoopLength(2.0);
  EXPECT_DOUBLE_EQ(sequence.GetLoopLength(), 2.0);
  sequence.SetEndPosition(9.5);
  EXPECT_DOUBLE_EQ(sequence.GetEndPosition(), 9.5);
  sequence.Process(0.0, 10.0);
  EXPECT_THAT(note_ons,
              ElementsAre(Pair(2.0, 0.0), Pair(3.0, 1.0), Pair(4.0, 2.0),
                          Pair(3.0, 3.0), Pair(4.0, 4.0), Pair(3.0, 5.0),
                          Pair(4.0, 6.0), Pair(3.0, 7.0), Pair(4.0, 8.0),
                          Pair(3.0, 9.0)));
  EXPECT_THAT(note_offs,
              ElementsAre(Pair(2.0, 1.0), Pair(3.0, 2.0), Pair(4.0, 3.0),
                          Pair(3.0, 4.0), Pair(4.0, 5.0), Pair(3.0, 6.0),
                          Pair(4.0, 7.0), Pair(3.0, 8.0), Pair(4.0, 9.0),
                          Pair(3.0, 9.5)));
  note_ons.clear();
  note_offs.clear();
  for (int i = 0; i < 4; ++i) {
    EXPECT_TRUE(sequence.DestroyNote(static_cast<Id>(i + 1)));
  }
  sequence.Process(0.0, 10.0);
  EXPECT_TRUE(note_ons.empty());
  EXPECT_TRUE(note_offs.empty());
}
TEST ( SequenceTest , ProcessMultipleNotes ) { Conductor conductor ; Transport transport ; transport . SetTempo ( 60.0 ) ; Sequence sequence ( conductor , transport ) ; EXPECT_THAT ( sequence . GetInstrument ( ) , IsNull ( ) ) ; std :: vector < std :: pair < double , double > > note_ons ; std :: vector < std :: pair < double , double > > note_offs ; Instrument instrument ( Instrument :: Definition ( { } ) , 1 ) ; instrument . SetNoteOnCallback ( [ & ] ( double pitch , double intensity , double timestamp ) { EXPECT_DOUBLE_EQ ( intensity , 1.0 ) ; note_ons . emplace_back ( pitch , timestamp ) ; } ) ; instrument . SetNoteOffCallback ( [ & ] ( double pitch , double timestamp ) { note_offs . emplace_back ( pitch , timestamp ) ; } ) ; sequence . SetInstrument ( & instrument ) ; EXPECT_THAT ( sequence . GetInstrument ( ) , & instrument ) ; for ( int i = 0 ; i < 4 ; ++ i ) { EXPECT_TRUE ( sequence . CreateNote ( static_cast < Id > ( i + 1 ) , Note :: Definition ( 1.0 , Note :: PitchDefinition :: AbsolutePitch ( static_cast < double > ( i + 1 ) ) ) , static_cast < double > ( i ) ) ) ; EXPECT_THAT ( sequence . GetNotePosition ( static_cast < Id > ( i + 1 ) ) , AllOf ( NotNull ( ) , Pointee ( static_cast < double > ( i ) ) ) ) ; } sequence . Process ( 0.0 , 4.0 ) ; EXPECT_THAT ( note_ons , ElementsAre ( Pair ( 1.0 , 0.0 ) , Pair ( 2.0 , 1.0 ) , Pair ( 3.0 , 2.0 ) , Pair ( 4.0 , 3.0 ) ) ) ; EXPECT_THAT ( note_offs , ElementsAre ( Pair ( 1.0 , 1.0 ) , Pair ( 2.0 , 2.0 ) , Pair ( 3.0 , 3.0 ) ) ) ; note_ons . clear ( ) ; note_offs . clear ( ) ; sequence . Stop ( ) ; EXPECT_TRUE ( note_ons . empty ( ) ) ; EXPECT_THAT ( note_offs , ElementsAre ( Pair ( 4.0 , 0.0 ) ) ) ; note_ons . clear ( ) ; note_offs . clear ( ) ; sequence . SetBeginOffset ( 1.0 ) ; EXPECT_DOUBLE_EQ ( sequence . GetBeginOffset ( ) , 1.0 ) ; sequence . SetLooping ( true ) ; EXPECT_TRUE ( sequence . IsLooping ( ) ) ; sequence . SetLoopBeginOffset ( 2.0 ) ; EXPECT_DOUBLE_EQ ( sequence . GetLoopBeginOffset ( ) , 2.0 ) ; sequence . SetLoopLength ( 2.0 ) ; EXPECT_DOUBLE_EQ ( sequence . GetLoopLength ( ) , 2.0 ) ; sequence . SetEndPosition ( 9.5 ) ; EXPECT_DOUBLE_EQ ( sequence . GetEndPosition ( ) , 9.5 ) ; sequence . Process ( 0.0 , 10.0 ) ; EXPECT_THAT ( note_ons , ElementsAre ( Pair ( 2.0 , 0.0 ) , Pair ( 3.0 , 1.0 ) , Pair ( 4.0 , 2.0 ) , Pair ( 3.0 , 3.0 ) , Pair ( 4.0 , 4.0 ) , Pair ( 3.0 , 5.0 ) , Pair ( 4.0 , 6.0 ) , Pair ( 3.0 , 7.0 ) , Pair ( 4.0 , 8.0 ) , Pair ( 3.0 , 9.0 ) ) ) ; EXPECT_THAT ( note_offs , ElementsAre ( Pair ( 2.0 , 1.0 ) , Pair ( 3.0 , 2.0 ) , Pair ( 4.0 , 3.0 ) , Pair ( 3.0 , 4.0 ) , Pair ( 4.0 , 5.0 ) , Pair ( 3.0 , 6.0 ) , Pair ( 4.0 , 7.0 ) , Pair ( 3.0 , 8.0 ) , Pair ( 4.0 , 9.0 ) , Pair ( 3.0 , 9.5 ) ) ) ; note_ons . clear ( ) ; note_offs . clear ( ) ; for ( int i = 0 ; i < 4 ; ++ i ) { EXPECT_TRUE ( sequence . DestroyNote ( static_cast < Id > ( i + 1 ) ) ) ; } sequence . Process ( 0.0 , 10.0 ) ; EXPECT_TRUE ( note_ons . empty ( ) ) ; EXPECT_TRUE ( note_offs . empty ( ) ) ; }
Tests that sequence processes multiple notes as expected.
Tests that sequence processes multiple notes as expected .
// Set instrument. // Create notes. // Process until the end of last note. // Stop the last note. // Set loop with offset. // Set end position. // Destroy all notes.