The Csound Blog By Jacob Joaquin http://csound.noisepages.com/ jacobjoaquin@gmail.com Required Samples: "110 Kool Skool II.wav" by BT Download BT44.zip @ http://www.archive.org/details/BT "BNGABetterArpeggio01.wav" by FlavioGaete Download FlavioGaete44.zip @ http://www.archive.org/details/FlavioGaete Both samples are licensed under Creative Commons Attribution 3.0 Unported http://creativecommons.org/licenses/by/3.0/ -g -odac sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 0dbfs = 1.0 ; Instrument numbers # define SetTempo # 1 # # define TempoClock # 2 # # define BeatMessage # 3 # # define TriggerLoop # 4 # # define PlayLoop # 5 # # define StopLoop # 6 # # define Metronome # 7 # ; Table numbers for stored samples # define Loop_a # 1 # # define Loop_s # 2 # ; Tempos of samples # define Loop_a_tempo # 110 # # define Loop_s_tempo # 130 # ; Load samples into tables itemp ftgen $Loop_a, 0, 0, 1, "./110 Kool Skool II.wav", 0, 4, 1 itemp ftgen $Loop_s, 0, 0, 1, "./BNGABetterArpeggio01.wav", 0, 4, 1 gaclock init 0 ; Tempo clock gkclock init 0 ; Downsampled version of Mistress clock gkbeat init 0 ; The current beat gktempo init 120 ; Tempo of tempo clock gkmetro_on init 0 ; Metronome on (1) or off(0) event_i "i", $SetTempo, 0, 1, 110 ; Set tempo of tempo clock phasor event_i "i", $TempoClock, 0, -1 ; Turn on tempo clock event_i "i", $TriggerLoop, 0, -1 ; Turn on triggering system instr $SetTempo gktempo = p4 ; Sets tempo of tempo clock turnoff endin instr $TempoClock ; Tempo clock phasors gaclock phasor gktempo / 60 gkclock downsamp gaclock ; Trigger new beat ktrigger trigger gkclock, 0.5, 1 if ktrigger == 1 then ; Increment absolute beat gkbeat = gkbeat + 1 ; Print current measure/beat/absolute_beat event "i", $BeatMessage, 0, 1 ; Trigger metronome events if gkmetro_on == 1 then if (gkbeat - 1) % 4 == 0 then event "i", $Metronome, 0, 0.125, 0.125, 880 else event "i", $Metronome, 0, 0.125, 0.125, 440 endif endif endif endin instr $BeatMessage ; Prints current measure/beat/absolute_beat ibeat = i(gkbeat) prints "Measure: %d ", floor((ibeat - 1) / 4) + 1 prints "Beat: %d ", (ibeat - 1) % 4 + 1 prints "AbsBeat: %d\n", ibeat turnoff endin instr $TriggerLoop ; Sense input from keyboard kres, k_keydown sensekey ktrigger changed k_keydown ichar_a strchar "a" ; Trigger/retrigger loop a ichar_z strchar "z" ; Stop loop a ichar_s strchar "s" ; Trigger/retrigger loop s ichar_x strchar "x" ; Stop loop s ichar_d strchar "d" ; Turn on metronome ichar_c strchar "c" ; Turn off metronome if ktrigger == 1 then ; Quantize event to beat koffset = (1 - gkclock) / (gktempo / 60) ; Trigger/Retrigger Loop a if kres == ichar_a then event "i", $PlayLoop + 0.1, koffset, -1, 0.5,\ $Loop_a, $Loop_a_tempo, 1 endif ; Stop Loop a if kres == ichar_z then event "i", $StopLoop, koffset, 1, $PlayLoop + 0.1 endif ; Trigger/Retrigger Loop s if kres == ichar_s then event "i", $PlayLoop + 0.2, koffset, -1, 0.2, $Loop_s,\ $Loop_s_tempo, 1 endif ; Stop Loop s if kres == ichar_x then event "i", $StopLoop, koffset, 1, $PlayLoop + 0.2 endif ; Turn on metronome if kres == ichar_d then gkmetro_on = 1 endif ; Turn off metronome if kres == ichar_c then gkmetro_on = 0 endif endif endin instr $PlayLoop iamp = p4 ; Amplitude ifn = p5 ; F-table of stored sample itempo = p6 ; Original tempo of sample ipitch_mod = p7 ; Alter pitch of sample a1 loscil iamp, gktempo / itempo * ipitch_mod, ifn, 1, 1 out a1 endin instr $StopLoop i_instr = p4 ; Instrument to turnoff turnoff2 i_instr, 4, 0 ; Turn off instrument turnoff ; Turn this off endin instr $Metronome idur = p3 ; Duration iamp = p4 ; Amplitude ifreq = p5 ; Frequency k1 line 1, idur, 0 a1 oscils iamp, ifreq, 1 out a1 * k1 endin e [10 * 60] ; Run for 10 minutes