コード例 #1
0
int main() {
  YSE::System().init();


  envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.f, 0.f, 0.2));
  envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.1f, 1.f, 4));
  envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.2f, 0.5f, 0.5, true));
  envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.5f, 0.6f, 0.5));
  envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.9f, 0.5f, 0.5, false, true));
  envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(1.0f, 0.f, 0.5));
  envelope.generate();
  envelope.saveToFile("ADSRtest");
  

  std::cout << "press e to exit." << std::endl;

  synth.create();
  synthVoice voice;
  synth.addVoices(&voice, 8, 1);
  sound.create(synth).play();

  int counter = 0;
  while (true) {

    // random player
    if (YSE::Random(10) == 0) {
      synth.noteOff(1, bassNote);
      bassNote = YSE::Random(30, 50);
      Flt vel = YSE::RandomF(0.8, 0.9);
      synth.noteOn(1, bassNote, vel);
    }

    // melody
    if (YSE::Random(6) == 0) {
      synth.noteOff(1, middleNote);
      synth.noteOff(1, middleNote - 3);
      middleNote = YSE::Random(55, 65);
      synth.noteOn(1, middleNote, YSE::RandomF(0.5, 0.7));
      synth.noteOn(1, middleNote - 3, YSE::RandomF(0.5, 0.7));
    }

    /*if (counter % 20 == 0) {
      synth.noteOn(1, 60, 0.3);
      synth.noteOn(1, 67, 0.3);
      synth.noteOff(1, 62);
      synth.noteOff(1, 70);
    }
    else if (counter % 10 == 0) {
      synth.noteOff(1, 60);
      synth.noteOff(1, 67);
      synth.noteOn(1, 62, 0.3);
      synth.noteOn(1, 70, 0.3);
    }*/

    counter++;

    if (_kbhit()) {
      char ch = _getch();
      switch (ch) {


      case 'e': goto exit;
      }
    }
    YSE::System().sleep(100);
    YSE::System().update();
  }


exit:
  YSE::System().close();
  return 0;
}