@@ -103,6 +103,7 @@ TEST_F(SoundBlocksTest, RegisterBlocks)
103103 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_playuntildone" , &SoundBlocks::compilePlayUntilDone));
104104 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_stopallsounds" , &SoundBlocks::compileStopAllSounds));
105105 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_seteffectto" , &SoundBlocks::compileSetEffectTo));
106+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_changeeffectby" , &SoundBlocks::compileChangeEffectBy));
106107 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_changevolumeby" , &SoundBlocks::compileChangeVolumeBy));
107108 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_setvolumeto" , &SoundBlocks::compileSetVolumeTo));
108109 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sound_volume" , &SoundBlocks::compileVolume));
@@ -655,6 +656,65 @@ TEST_F(SoundBlocksTest, SetEffectToImpl)
655656 ASSERT_EQ (vm.registerCount (), 0 );
656657}
657658
659+ TEST_F (SoundBlocksTest, ChangeEffectBy)
660+ {
661+ Compiler compiler (&m_engineMock);
662+
663+ // change [pitch] effect by (5.3)
664+ auto block1 = std::make_shared<Block>(" a" , " sound_changeeffectby" );
665+ addDropdownField (block1, " EFFECT" , SoundBlocks::EFFECT, " PITCH" , SoundBlocks::PITCH);
666+ addValueInput (block1, " VALUE" , SoundBlocks::VALUE, 5.3 );
667+
668+ // change [pan] effect by (-79.52)
669+ auto block2 = std::make_shared<Block>(" b" , " sound_changeeffectby" );
670+ addDropdownField (block2, " EFFECT" , SoundBlocks::EFFECT, " PAN" , SoundBlocks::PAN);
671+ addValueInput (block2, " VALUE" , SoundBlocks::VALUE, -79.52 );
672+
673+ compiler.init ();
674+
675+ EXPECT_CALL (m_engineMock, functionIndex (&SoundBlocks::changePitchEffectBy)).WillOnce (Return (0 ));
676+ compiler.setBlock (block1);
677+ SoundBlocks::compileChangeEffectBy (&compiler);
678+
679+ EXPECT_CALL (m_engineMock, functionIndex (&SoundBlocks::changePanEffectBy)).WillOnce (Return (1 ));
680+ compiler.setBlock (block2);
681+ SoundBlocks::compileChangeEffectBy (&compiler);
682+
683+ compiler.end ();
684+
685+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_CONST, 1 , vm::OP_EXEC, 1 , vm::OP_HALT }));
686+ ASSERT_EQ (compiler.constValues (), std::vector<Value>({ 5.3 , -79.52 }));
687+ }
688+
689+ TEST_F (SoundBlocksTest, ChangeEffectByImpl)
690+ {
691+ static unsigned int bytecode1[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT };
692+ static unsigned int bytecode2[] = { vm::OP_START, vm::OP_CONST, 1 , vm::OP_EXEC, 1 , vm::OP_HALT };
693+ static BlockFunc functions[] = { &SoundBlocks::changePitchEffectBy, &SoundBlocks::changePanEffectBy };
694+ static Value constValues[] = { -20.7 , 12.53 };
695+
696+ TargetMock target;
697+ VirtualMachine vm (&target, nullptr , nullptr );
698+
699+ vm.setBytecode (bytecode1);
700+ vm.setFunctions (functions);
701+ vm.setConstValues (constValues);
702+
703+ EXPECT_CALL (target, soundEffect (Sound::Effect::Pitch)).WillOnce (Return (56 ));
704+ EXPECT_CALL (target, setSoundEffect (Sound::Effect::Pitch, 35.3 ));
705+ vm.run ();
706+
707+ ASSERT_EQ (vm.registerCount (), 0 );
708+
709+ EXPECT_CALL (target, soundEffect (Sound::Effect::Pan)).WillOnce (Return (-2.5 ));
710+ EXPECT_CALL (target, setSoundEffect (Sound::Effect::Pan, 10.03 ));
711+ vm.reset ();
712+ vm.setBytecode (bytecode2);
713+ vm.run ();
714+
715+ ASSERT_EQ (vm.registerCount (), 0 );
716+ }
717+
658718TEST_F (SoundBlocksTest, ChangeVolumeBy)
659719{
660720 Compiler compiler (&m_engineMock);
0 commit comments