0
我正在寫一個合成器與管道和舞臺架構。我目前用這種方式創建我的階段:替代工廠(類設計)
的main.cpp
Stage *s1 = pipeLine.AddStage(StageRegistry::StageId::SIN_OSCILLATOR);
Stage *s2 = pipeLine.AddStage(StageRegistry::StageId::WAVE16BIT_WRITER);
Stage *s3 = pipeLine.AddStage(StageRegistry::StageId::LINEAR_ENVELOPE);
Stage *s4 = pipeLine.AddStage(StageRegistry::StageId::MULTIPLIER);
我使用在一個名爲StageRegistry類的工廠方法。很明顯,每個專門的舞臺類都有可變的參數,這對我來說不會奏效。我目前硬編碼的所有構造函數PARAMS:
StageRegistry.cpp
Stage* StageRegistry::CreateStage(const StageId stageId)
{
Stage *s = nullptr;
switch (stageId)
{
case StageId::SIN_OSCILLATOR:
{
return new SinOscillator(48);
}
break;
case StageId::WAVE16BIT_WRITER:
{
return new WaveFileWriter("out1.wav", 1);
}
break;
case StageId::LINEAR_ENVELOPE:
{
return new LinearEnvelope(0.2f, 0.3f, 0.8f);
}
case StageId::MULTIPLIER:
{
return new Multiplier();
}
break;
}
return s;
}
我有什麼辦法?重要的是我要返回一個Generic Stage *類,以避免轉換爲管道連接的特定類。
的main.cpp
SharedBuffer *sb0 = pipeLine.CreatePipe();
SharedBuffer *sb1 = pipeLine.CreatePipe();
SharedBuffer *sb2 = pipeLine.CreatePipe();
s1->SetOutputPipe(0, sb0);
s3->SetOutputPipe(0, sb1);
s4->SetInputPipe(0, sb0);
s4->SetInputPipe(1, sb1);
s4->SetOutputPipe(0, sb2);
s2->SetInputPipe(0, sb2);
我在我的建築真的早,所以我想正確地釘下來,一些文獻和一般的建議是我想什麼。我不確定我想要什麼。