barelymusician/engine/engine_test.cpp
// Tests that engine plays sequence as expected.
Tests that engine plays sequence as expected.
Tests that engine plays sequence as expected .
TEST(EngineTest, PlaySequence) {
  const Id kInstrumentId = 1;
  const Id kSequenceId = 2;
  const Id kNoteId = 3;
  const Note::Definition kNoteDefinition = {
      5.0, Note::PitchDefinition::RelativePitch(1.0)};
  const double kRootNote = 0.5;
  Engine engine;
  EXPECT_THAT(engine.GetInstrument(kInstrumentId), IsNull());
  EXPECT_THAT(engine.GetSequence(kSequenceId), IsNull());
  engine.GetConductor().SetRootNote(kRootNote);
  EXPECT_DOUBLE_EQ(engine.GetConductor().GetRootNote(), kRootNote);
  EXPECT_TRUE(engine.CreateInstrument(
      kInstrumentId, GetTestInstrumentDefinition(), kFrameRate));
  auto* instrument = engine.GetInstrument(kInstrumentId);
  EXPECT_THAT(instrument, NotNull());
  EXPECT_TRUE(engine.CreateSequence(kSequenceId));
  auto* sequence = engine.GetSequence(kSequenceId);
  EXPECT_THAT(sequence, NotNull());
  EXPECT_TRUE(engine.SetSequenceInstrumentId(kSequenceId, kInstrumentId));
  EXPECT_THAT(engine.GetSequenceInstrumentId(kSequenceId),
              AllOf(NotNull(), Pointee(kInstrumentId)));
  EXPECT_TRUE(sequence->CreateNote(kNoteId, kNoteDefinition, 1.0));
  EXPECT_FALSE(instrument->IsNoteOn(kRootNote + 1.0));
  engine.GetTransport().SetTempo(60.0);
  EXPECT_DOUBLE_EQ(engine.GetTransport().GetTempo(), 60.0);
  EXPECT_FALSE(engine.GetTransport().IsPlaying());
  engine.Start();
  EXPECT_TRUE(engine.GetTransport().IsPlaying());
  engine.Update(1.0);
  EXPECT_DOUBLE_EQ(engine.GetTransport().GetPosition(), 1.0);
  EXPECT_FALSE(instrument->IsNoteOn(kRootNote + 1.0));
  engine.Update(1.5);
  EXPECT_DOUBLE_EQ(engine.GetTransport().GetPosition(), 1.5);
  EXPECT_TRUE(instrument->IsNoteOn(kRootNote + 1.0));
  instrument->StartNote(engine.GetConductor().GetRootNote(), 1.0, 1.5);
  EXPECT_TRUE(instrument->IsNoteOn(engine.GetConductor().GetRootNote()));
  engine.Stop();
  EXPECT_FALSE(instrument->IsNoteOn(kRootNote + 1.0));
  EXPECT_TRUE(instrument->IsNoteOn(engine.GetConductor().GetRootNote()));
  EXPECT_TRUE(engine.DestroySequence(kSequenceId));
  EXPECT_THAT(engine.GetSequence(kSequenceId), IsNull());
  EXPECT_TRUE(instrument->IsNoteOn(engine.GetConductor().GetRootNote()));
  EXPECT_TRUE(engine.DestroyInstrument(kInstrumentId));
  EXPECT_THAT(engine.GetInstrument(kInstrumentId), IsNull());
}
TEST ( EngineTest , PlaySequence ) { const Id kInstrumentId = 1 ; const Id kSequenceId = 2 ; const Id kNoteId = 3 ; const Note :: Definition kNoteDefinition = { 5.0 , Note :: PitchDefinition :: RelativePitch ( 1.0 ) } ; const double kRootNote = 0.5 ; Engine engine ; EXPECT_THAT ( engine . GetInstrument ( kInstrumentId ) , IsNull ( ) ) ; EXPECT_THAT ( engine . GetSequence ( kSequenceId ) , IsNull ( ) ) ; engine . GetConductor ( ) . SetRootNote ( kRootNote ) ; EXPECT_DOUBLE_EQ ( engine . GetConductor ( ) . GetRootNote ( ) , kRootNote ) ; EXPECT_TRUE ( engine . CreateInstrument ( kInstrumentId , GetTestInstrumentDefinition ( ) , kFrameRate ) ) ; auto * instrument = engine . GetInstrument ( kInstrumentId ) ; EXPECT_THAT ( instrument , NotNull ( ) ) ; EXPECT_TRUE ( engine . CreateSequence ( kSequenceId ) ) ; auto * sequence = engine . GetSequence ( kSequenceId ) ; EXPECT_THAT ( sequence , NotNull ( ) ) ; EXPECT_TRUE ( engine . SetSequenceInstrumentId ( kSequenceId , kInstrumentId ) ) ; EXPECT_THAT ( engine . GetSequenceInstrumentId ( kSequenceId ) , AllOf ( NotNull ( ) , Pointee ( kInstrumentId ) ) ) ; EXPECT_TRUE ( sequence -> CreateNote ( kNoteId , kNoteDefinition , 1.0 ) ) ; EXPECT_FALSE ( instrument -> IsNoteOn ( kRootNote + 1.0 ) ) ; engine . GetTransport ( ) . SetTempo ( 60.0 ) ; EXPECT_DOUBLE_EQ ( engine . GetTransport ( ) . GetTempo ( ) , 60.0 ) ; EXPECT_FALSE ( engine . GetTransport ( ) . IsPlaying ( ) ) ; engine . Start ( ) ; EXPECT_TRUE ( engine . GetTransport ( ) . IsPlaying ( ) ) ; engine . Update ( 1.0 ) ; EXPECT_DOUBLE_EQ ( engine . GetTransport ( ) . GetPosition ( ) , 1.0 ) ; EXPECT_FALSE ( instrument -> IsNoteOn ( kRootNote + 1.0 ) ) ; engine . Update ( 1.5 ) ; EXPECT_DOUBLE_EQ ( engine . GetTransport ( ) . GetPosition ( ) , 1.5 ) ; EXPECT_TRUE ( instrument -> IsNoteOn ( kRootNote + 1.0 ) ) ; instrument -> StartNote ( engine . GetConductor ( ) . GetRootNote ( ) , 1.0 , 1.5 ) ; EXPECT_TRUE ( instrument -> IsNoteOn ( engine . GetConductor ( ) . GetRootNote ( ) ) ) ; engine . Stop ( ) ; EXPECT_FALSE ( instrument -> IsNoteOn ( kRootNote + 1.0 ) ) ; EXPECT_TRUE ( instrument -> IsNoteOn ( engine . GetConductor ( ) . GetRootNote ( ) ) ) ; EXPECT_TRUE ( engine . DestroySequence ( kSequenceId ) ) ; EXPECT_THAT ( engine . GetSequence ( kSequenceId ) , IsNull ( ) ) ; EXPECT_TRUE ( instrument -> IsNoteOn ( engine . GetConductor ( ) . GetRootNote ( ) ) ) ; EXPECT_TRUE ( engine . DestroyInstrument ( kInstrumentId ) ) ; EXPECT_THAT ( engine . GetInstrument ( kInstrumentId ) , IsNull ( ) ) ; }
Tests that engine plays sequence as expected.
Tests that engine plays sequence as expected .
// Set root note. // Create instrument. // Create sequence. // Set sequence instrument. // Create note. // Start playback with one beat per second tempo. // Update timestamp just before the start position of the note. // Update timestamp past the start position, but before the note ends. // Start another note manually. // Stop playback, which should only stop the sequence note. // Destroy sequence, which should not affect the instrument. // Destroy instrument.