Extra "ports" of juce-based plugins using the distrho build system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
6.5KB

  1. Metronome.csd
  2. For the best timing accuracy, set ksmps = 1
  3. Iain McCurdy, 2013
  4. ; level 1 - amplitude level for the main 'beat' (1st beat of the bar)
  5. ; level 2 - amplitude level for other beats of the bar (subdivisions)
  6. ; Subdiv. - subdivision of the bar. i.e. 4 for 4/4, 3 for 3/4 etc.
  7. ; tone 1 - tone of the main beat (1st beat of the bar)
  8. ; tone 2 - tone level for other beats of the bar (subdivisions)
  9. ; duration - duration of each 'click'
  10. ; width - stereo width of each click
  11. ; to achieve a simple 1 click metronome, set level 2 to zero and subdiv to 1.
  12. A simple Cabbage metronome
  13. <Cabbage>
  14. form caption("Metronome"), size(770,140), pluginID("mtro")
  15. image bounds( 0, 0,770,140), colour(160, 70,20,100), shape("rounded"), outline("white"), line(4)
  16. checkbox bounds( 15, 20,130, 40), text("Start/Stop") channel("OnOff"), FontColour("White"), colour(250,250,100) value(0)
  17. rslider bounds(120, 13, 65, 65), text("Level 1"), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("level1"), range(0, 1.00, 0.4, 0.5, 0.001)
  18. rslider bounds(180, 13, 65, 65), text("Level 2"), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("level2"), range(0, 1.00, 0.1, 0.5, 0.001)
  19. rslider bounds(240, 13, 65, 65), text("Subdiv."), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("subdiv"), range(1, 16, 3, 1, 1)
  20. rslider bounds(300, 13, 65, 65), text("Tone 1"), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("tone1"), range(0, 4.00, 2.5)
  21. rslider bounds(360, 13, 65, 65), text("Tone 2"), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("tone2"), range(0, 4.00, 1.56)
  22. rslider bounds(420, 13, 65, 65), text("Duration"), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("dur"), range(0.003, 0.1, 0.012, 0.5, 0.00001)
  23. rslider bounds(480, 13, 65, 65), text("Width"), colour(160, 70,20,100), trackercolour(250,250,200), FontColour("White"), channel("width"), range(0, 2.00, 0)
  24. checkbox bounds(550, 18, 45, 45) channel("indicator"), FontColour("White"), colour(255, 50, 50) value(0), shape("ellipse")
  25. checkbox bounds(600, 18, 45, 45) channel("indicator2"), FontColour("White"), colour(100,255,100) value(0), shape("ellipse")
  26. hslider bounds( 10, 75,750, 40), colour(160, 70,20,100), trackercolour(160, 70, 20,100), FontColour("White"), channel("tempo"), range(10,1000, 90, 1, 1) textBox(1)
  27. label bounds(345, 110, 80, 12), text("Tempo [BPM]"), fontcolour("white")
  28. groupbox bounds(655, 25,1030, 520), colour(160, 70,20,100), line(0), popup(1), plant("Large LEDs"){
  29. checkbox bounds( 10, 10,500,500) channel("indicator"), FontColour("White"), colour(255, 50, 50) value(0), shape("ellipse")
  30. checkbox bounds(520, 10,500,500) channel("indicator2"), FontColour("White"), colour(100,255,100) value(0), shape("ellipse")
  31. }
  32. label bounds( 10,120, 200, 12), text("Author: Iain McCurdy |2013|"), FontColour("silvers")
  33. </Cabbage>
  34. <CsoundSynthesizer>
  35. <CsOptions>
  36. -dm0 -n -+rtmidi=null -M0
  37. </CsOptions>
  38. <CsInstruments>
  39. sr = 44100
  40. ksmps = 16 ; for maximum timing accuracy set ksmps = 1
  41. nchnls = 2
  42. 0dbfs = 1 ;MAXIMUM AMPLITUDE
  43. gistrt ftgen 0,0,8,-2, 200, 200, 2500, 5000, 5000
  44. giend ftgen 0,0,8,-2, 20, 1000, 20, 20, 1000
  45. gisine ftgen 0,0,4096,10,1 ; sine wave (used by the audio oscillator)
  46. gasend init 0 ; global variable used to send audio to the 'stereo' instrument
  47. gibar ftgen 0,0,64,-2,1 ; bar structure basically a '1' followed by 63 zeroes, '1' indicating the first neat of a bar and zero indicating any other beat
  48. instr 1
  49. kOnOff chnget "OnOff"
  50. kdur chnget "dur"
  51. ksubdiv chnget "subdiv"
  52. ktone1 chnget "tone1"
  53. ktone2 chnget "tone2"
  54. klevel1 chnget "level1"
  55. klevel2 chnget "level2"
  56. kstrt tablei ktone1,gistrt
  57. kend tablei ktone1,giend
  58. kstrt2 tablei ktone2,gistrt
  59. kend2 tablei ktone2,giend
  60. ; restart metronome if subdiv changes to ensure timing accuracy
  61. ktrig changed ksubdiv,kOnOff
  62. if ktrig==1 then
  63. reinit RESTART
  64. endif
  65. RESTART:
  66. kbeat init 0 ; initialise beat position (0 = first beat of the bar)
  67. if kOnOff==1 then
  68. gktempo chnget "tempo"
  69. kmetro metro gktempo/60 ; bar metronome
  70. if kmetro=1 then ; if a beat is occuring...
  71. ktype table kbeat,gibar ;1=bar 0=beat ; read if this is a first beat of a bar or not (1=first beat, 0=any other)
  72. if ktype=1 then ; if first beat of a bar...
  73. event "i",2,0,kdur,kstrt,kend,klevel1,1 ; ... call metronome click as if 1st beat (p7 = 1 = flash indicator)
  74. else ; otherwise (must be aby other beat of a bar)...
  75. event "i",2,0,kdur,kstrt2,kend2,klevel2,0 ; ...call metronome click as if any other beat of a bar (p7 = 0 = don't flash indicator)
  76. endif
  77. kbeat wrap kbeat+1, 0, ksubdiv ; increment beat position but wrap around to zero if final beat of a bar has already been reacxhed
  78. endif
  79. endif
  80. endin
  81. instr 2 ; produce metronome sound (this instrument will be called repeatedly)
  82. iwidth chnget "width"
  83. acps transeg p4,p3,-7,p5 ; pitch of oscillator (a quickly decaying exponential curve) start='tone 1', end='tone 2'
  84. aenv transeg 1,p3,-7,0 ; amplitude of oscillator (a quickly decaying exponential curve)
  85. asig oscili p6,acps,gisine ; audio oscillator
  86. amod oscili 3,200,gisine ; modulation signal
  87. asig = asig*amod ; ring modulate original audio signal
  88. asig butbp asig*10,100,100 ; bandpass filter the sound to attenuate lows and highs
  89. asig = asig*aenv ; apply envelope
  90. outs asig,asig ; send audio to outputs
  91. gasend = gasend+asig*iwidth ; send a bit of the audio to the stereo-ifying instrument
  92. event_i "i",5-p7,0,0.08 ; flash indicator (call instrument 4 for 0.1 duration)
  93. endin
  94. instr 3 ; 'stereo'ify the sound
  95. aL delay gasend, rnd(0.01) ; slightly delay audio by a random amount to create left channel audio
  96. aR delay gasend, rnd(0.01) ; slightly delay audio by a random amount to create right channel audio
  97. aL butlp aL,cpsoct(rnd(10)) ; filter left channel (random cutoff frequency)
  98. aR butlp aR,cpsoct(rnd(10)) ; filter right channel (random cutoff frequency)
  99. outs aL,aR ; send audio to outputs
  100. gasend = 0 ; clear global send variable
  101. endin
  102. instr 4 ; flash red indicator
  103. gkrelease release ; krelease=0 while note is active, =1 when note ends (final k-cycle)
  104. chnset 1-gkrelease,"indicator" ; turn indicator on or off
  105. endin
  106. instr 5 ; flash green indicator
  107. gkrelease release ; krelease=0 while note is active, =1 when note ends (final k-cycle)
  108. chnset 1-gkrelease,"indicator2" ; turn indicator on or off
  109. endin
  110. </CsInstruments>
  111. <CsScore>
  112. i 1 0 [60*60*24*7]
  113. i 3 0 [60*60*24*7]
  114. </CsScore>
  115. </CsoundSynthesizer>