Csound Csound-dev Csound-tekno Search About

midi toggles

Date2006-03-22 02:11
FromJonathan Murphy
Subjectmidi toggles
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi Folks,

I'm working on a realtime midi-controlled FM synthesizer. The basis of
the instrument is taken from a blueshare instrument: 4 FM Oscillators
by mbechard. There are eight oscillators in total. Each oscillator has 
four waveshapes available (sine, square, sawtooth, triangle). What I 
would like to be able to do is toggle between these waveshapes. I
could do it using pgmassign, but then I would have 32 instruments,
identical except for one number. The thread started by David Akbari a
few days ago, 'Simulating a "bang," gave me the idea that it might be 
possible to do things with a bit more style. What I would like to do
is to assign a button to each oscillator, and have them cycle through
the waveshapes (incremental program change?). Any ideas on how to do
this would be appreciated.

Thanks,
Jonathan.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 

iD8DBQFEILI6CibrChMdb1sRAgbDAJ9raRGx6/H06sQkocCuR2onX0ydQACglJqr
Mb3L2YH0CBrEmcvd/F0fLyo=
=GrvW
-----END PGP SIGNATURE-----

Date2006-03-22 08:49
FromDavid Akbari
SubjectRe: midi toggles
Hi Jonathan,

since you mentioned my name in your email, please accept my humble 
example demonstrating what i think you may be after.

it uses one of my UDO's that was designed after Dr. B's foot array that 
sends out MIDI program change messages (manual here: 
http://www.csounds.com/udo/displayOpcode.php?opcode_id=71)

basically if you send program change 2 on channel 1, it will increment 
the table. if you send program change 3 on channel 1 it will decrement 
which table is being used.

the key idea is using a global variable that stores each "tick" and 
then using a modulus operator to control the flow to the desired 
amount. in this case 4 tables, (sine, square, saw, triangle)

when you change the table, the number of the table currently being used 
is printed to the stdout.

hope this helps!





sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2
	massign	1, 2

itmp	ftgen	1, 0, 16384, 10, 1	; sine
itmp	ftgen	2, 0, 16384, 10, 1, (1/3), (1/5), (1/7), (1/9), (1/11), 
(1/13), (1/15) ; square
itmp	ftgen	3, 0, 16384, 10, 1, (1/2), (1/3), (1/4), (1/5), (1/6), 
(1/7), (1/8),\
					(1/9), (1/10), (1/11), (1/12), (1/13), (1/14), (1/15), (1/16) ; saw
itmp	ftgen	4, 0, 16384, 7, 0, 4096, 1, 4096, 0, 4096, -1, 4096, 0	; 
triangle

gkcount	init	0

;//
		opcode  footarray, kk, 0

kstatus, kchan, kd1, kd2        midiin
kval  =  0

if      (kstatus == 176 && kd1 == 32) then
kval    =       0
elseif  (kstatus == 192) then
knum    =       kd1
kval    =       1
         endif

	xout    knum, kval

		endop
;//

/*--- ---*/

		instr	1

kmod	ctrl7	1, 1, 0, 2

knum, kval      footarray

if	(knum == 1 && kval == 1) kgoto inc
if	(knum == 2 && kval == 1) kgoto dec
         kgoto   contin

   inc:
gkcount	=	((gkcount + 1) % 4)
printk2	(gkcount+1)
kgoto   contin

   dec:
gkcount	=	((gkcount - 1) % 4)
printk2	(gkcount+1)
kgoto   contin

   contin:
knum    =       0
                 endin

/*--- ---*/

                 instr   2

iamp	ampmidi	10000
kcps	cpsmidib	2

a1	oscil	iamp, kcps, (i(gkcount)+1)

	outs	a1, a1

                 endin

/*--- ---*/



i1	0	3600

e

;# EOF



-David

On Mar 21, 2006, at 9:11 PM, Jonathan Murphy wrote:

> What I would like to do
> is to assign a button to each oscillator, and have them cycle through
> the waveshapes (incremental program change?). Any ideas on how to do
> this would be appreciated.