barelymusician/engine/engine_test.cpp
// Tests that multiple instruments are created and destroyed as expected.
Tests that multiple instruments are created and destroyed as expected.
Tests that multiple instruments are created and destroyed as expected .
TEST(EngineTest, CreateDestroyMultipleInstruments) {
  std::vector<double> note_off_pitches;
  {
    Engine engine;
    for (int i = 0; i < 3; ++i) {
      const Id instrument_id = i + 1;
      EXPECT_THAT(engine.GetInstrument(instrument_id), IsNull());
      EXPECT_TRUE(engine.CreateInstrument(
          instrument_id, GetTestInstrumentDefinition(), kFrameRate));
      EXPECT_THAT(engine.GetInstrument(instrument_id), NotNull());
      engine.GetInstrument(instrument_id)
          ->SetNoteOffCallback([&](double pitch, double ) {
            note_off_pitches.push_back(pitch);
          });
    }
    for (int i = 0; i < 3; ++i) {
      engine.GetInstrument(i + 1)->StartNote(static_cast<double>(i + 1), 1.0,
                                             0.0);
      engine.GetInstrument(i + 1)->StartNote(static_cast<double>(-i - 1), 1.0,
                                             0.0);
      engine.GetInstrument(i + 1)->StopNote(static_cast<double>(i + 1), 0.0);
    }
    EXPECT_THAT(note_off_pitches, ElementsAre(1.0, 2.0, 3.0));
  }
  EXPECT_THAT(note_off_pitches,
              UnorderedElementsAre(-3.0, -2.0, -1.0, 1.0, 2.0, 3.0));
}
TEST ( EngineTest , CreateDestroyMultipleInstruments ) { std :: vector < double > note_off_pitches ; { Engine engine ; for ( int i = 0 ; i < 3 ; ++ i ) { const Id instrument_id = i + 1 ; EXPECT_THAT ( engine . GetInstrument ( instrument_id ) , IsNull ( ) ) ; EXPECT_TRUE ( engine . CreateInstrument ( instrument_id , GetTestInstrumentDefinition ( ) , kFrameRate ) ) ; EXPECT_THAT ( engine . GetInstrument ( instrument_id ) , NotNull ( ) ) ; engine . GetInstrument ( instrument_id ) -> SetNoteOffCallback ( [ & ] ( double pitch , double ) { note_off_pitches . push_back ( pitch ) ; } ) ; } for ( int i = 0 ; i < 3 ; ++ i ) { engine . GetInstrument ( i + 1 ) -> StartNote ( static_cast < double > ( i + 1 ) , 1.0 , 0.0 ) ; engine . GetInstrument ( i + 1 ) -> StartNote ( static_cast < double > ( - i - 1 ) , 1.0 , 0.0 ) ; engine . GetInstrument ( i + 1 ) -> StopNote ( static_cast < double > ( i + 1 ) , 0.0 ) ; } EXPECT_THAT ( note_off_pitches , ElementsAre ( 1.0 , 2.0 , 3.0 ) ) ; } EXPECT_THAT ( note_off_pitches , UnorderedElementsAre ( -3.0 , -2.0 , -1.0 , 1.0 , 2.0 , 3.0 ) ) ; }
Tests that multiple instruments are created and destroyed as expected.
Tests that multiple instruments are created and destroyed as expected .
// Create instruments with note off callback. /*timestamp*/ // Start multiple notes, then immediately stop some of them. // Remaining active notes should be stopped once the engine goes out of scope.