Sampler in ChucK
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

45 行
790B

  1. // the event
  2. KBHit kb;
  3. class MetronomeEvent extends Event{ int value; }
  4. class Metronome {
  5. MetronomeEvent metronomeEvent;
  6. spork ~pulse();
  7. fun void listen(){
  8. while (true){
  9. metronomeEvent => now;
  10. <<<"Metronome got event " + metronomeEvent.value>>>;
  11. if (metronomeEvent.value==0){
  12. spork ~pulse();
  13. }
  14. }
  15. }
  16. fun void pulse(){
  17. 1::second => now;
  18. 0=>metronomeEvent.value;
  19. metronomeEvent.signal();
  20. }
  21. fun void signal(){
  22. 1=>metronomeEvent.value;
  23. metronomeEvent.signal();
  24. }
  25. }
  26. Metronome m;
  27. spork ~m.listen();
  28. // time-loop
  29. while( true )
  30. {
  31. kb => now;
  32. while( kb.more() )
  33. {
  34. <<< "ascii: ", kb.getchar() >>>;
  35. m.signal();
  36. }
  37. }