Try   HackMD

開發紀錄 Week3

UI Screenshot

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

UI details

Combobox

  • 藉由Combobox來選擇欲呈現的波型
  • 將各種波型加入ComboBox中
synthChoose.addItem("Sine",1); synthChoose.addItem("Square", 2); synthChoose.addItem("Sawtooth", 3); synthChoose.addItem("Triangle", 4);
  • 利用addAndMakeVisible(synthChoose); 將按鈕加入UI
  • 最後記得resize combobox的位置
  • synthChoose.setBounds(x, y + 50, sliderWidth, sliderHeight);

AudioProcessorValueTreeState

  • 將Combobox接收到的數值,送至這個Tree中儲存
waveComboBoxAttachment.reset(new juce::AudioProcessorValueTreeState ::ComboBoxAttachment(audioProcessor.tree, "wave", synthChoose));
  • 之後在Processer端利用getRawParameterValue()做接收
myVoice->setChannel(tree.getRawParameterValue("wave")->load());

Generate Wave Value

Square wave

  • 藉由sin(currentAngle)判斷當前象限,若為一二象限為+1,否則為-1
value = ((std::sin(currentAngle) > 0) ? 1 : -1) ;

Sawtooth wave

  • 想法是先算出currentAngle在twoPi中的比例(藉由將currentAngle+Pi調整起始位置)
proportion = fmod(currentAngle + juce::MathConstants<float>::pi, juce::MathConstants<float>::twoPi) / juce::MathConstants<float>::twoPi;
  • 將斜率代入後再將value調整至1~-1之間即可
value = (proportion * 2 - 1);

Triangle wave

  • 和鋸齒波想法相似,一樣是先將比例算出(藉由將currentAngle+halfPi調整起始位置)
proportion = fmod(currentAngle + juce::MathConstants<float>::halfPi, juce::MathConstants<float>::twoPi) / juce::MathConstants<float>::twoPi;
  • 但三角波有兩條不一樣的線,所以分別在 0~0.5 用一斜率 0.5~1 用另一斜率,再將value調整至1~-1
if (proportion < 0.5) value = ((proportion * 2) * 2 - 1); else value = 2 - ((proportion - 0.5) * 2) * 2 - 1;