Csound Csound-dev Csound-tekno Search About

Re: Simulating a "bang"

Date2006-03-17 17:43
From"Art Hunkins"
SubjectRe: Simulating a "bang"
To further develop, how about:

ktog init 0
kstatus, kchan, kdata1, kdata2 midiin
ktog = ((kstatus == 192) && (kdata1 == pgm#))? 1-ktog: ktog)

Art Hunkins

----- Original Message ----- 
From: "Chuckk Hubbard" 
To: 
Sent: Friday, March 17, 2006 11:16 AM
Subject: Re: [Csnd] Simulating a "bang"


ktog = 1-ktog?
Then whatever trigger you want could goto that segment.
For a bang, what about "trigger" w mode 2.


On 3/17/06, David Akbari  wrote:
> Hi List,
>
> What's the easiest way to simulate a bang a la Pure Data ?
>
> I ask because of the idea of implementing toggles, switches, et al
>
> My idea is simply to send for example program change message with value
> "1" having this value toggle some arbitrary parameter... such an idea
> is trivial in Pd but I am uncertain of a really good and efficient way
> to do this in Csound.
>
> How can I make a variable = 1 when program change 1 is sent then
> variable = 0 when this same message is received a second time ?
>
> TIA,
>
>
> -David
>
> --
> Send bugs reports to this list.
> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
>


--
"It is not when truth is dirty, but when it is shallow, that the lover
of knowledge is reluctant to step into its waters."
-Friedrich Nietzsche, "Thus Spoke Zarathustra"
-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2006-03-19 02:05
FromDavid Akbari
SubjectRe: Simulating a "bang"
Thank you both, Art and Chuckk.

I have found the idea of the question mark "syntactic sugar" to be a 
very good solution.

Trigger with mode 2 should also work well but I like the question mark 
idea because it can also be used to implement hysteresis among many 
other things. It's likely I will be using both.

Thank you both once again for your help!


-David

On Mar 17, 2006, at 12:43 PM, Art Hunkins wrote:

> To further develop, how about:
>
> ktog init 0
> kstatus, kchan, kdata1, kdata2 midiin
> ktog = ((kstatus == 192) && (kdata1 == pgm#))? 1-ktog: ktog)
>
> Art Hunkins
>
> ----- Original Message -----
> From: "Chuckk Hubbard" 
> To: 
> Sent: Friday, March 17, 2006 11:16 AM
> Subject: Re: [Csnd] Simulating a "bang"
>
>
> ktog = 1-ktog?
> Then whatever trigger you want could goto that segment.
> For a bang, what about "trigger" w mode 2.

Date2006-03-24 08:46
FromDavid Akbari
SubjectRe: Simulating a "bang"
As a followup to this thread, here is the way I ended up implementing 
it. I post this purely out of fondness for pedagogy.

The GUI basically just uses a checkbox object in Ma++'s MacCsound which 
is basically just a named channel that accepts values 0 and 1, for off 
and on respectively.

Incidentally, is there a way to disable Csound's default behavior of 
changing which instrument MIDI input is assigned to via program change 
messages ?





; one checkbox version
;  the idea is get program change message 2 in
;  display a toggle on the GUI checkbox

sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2

gkcheck1	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

knum, kval	footarray

if	(knum == 1 && kval == 1) then
gkcheck1	=	(gkcheck1 + 1) % 2
else
	endif

	outvalue	"checkbex1", gkcheck1
	printk2	gkcheck1

		endin

/*--- ---*/



i1	0	3600

e




Version: 3
Render: Real
Ask: Yes
Functions: ioObject
WindowBounds: 242 44 914 789
Options: -b1024 -A -s -m7 -K -R


ioView background {0, 3818, 65535}
ioListing {7, 3} {374, 642}
ioCheckbox {436, 73} {30, 30} off checkbex1








; 4 checkbox version
;  uses pgm change messages
;  2-5

sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2

gkcheck1	init	0
gkcheck2	init	0
gkcheck3	init	0
gkcheck4	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

knum, kval	footarray

if	(knum == 1 && kval == 1) then
gkcheck1	=	(gkcheck1 + 1) % 2
elseif	(knum == 2 && kval == 1) then
gkcheck2	=	(gkcheck2 + 1) % 2
elseif	(knum == 3 && kval == 1) then
gkcheck3	=	(gkcheck3 + 1) % 2
elseif	(knum == 4 && kval == 1) then
gkcheck4	=	(gkcheck4 + 1) % 2
else
	endif

	outvalue	"checkbex1", gkcheck1
	outvalue	"checkbex2", gkcheck2
	outvalue	"checkbex3", gkcheck3
	outvalue	"checkbex4", gkcheck4

;	printk2	gkcheck1
;	printk2	gkcheck2
;	printk2	gkcheck3
;	printk2	gkcheck4

		endin

/*--- ---*/



i1	0	3600

e




Version: 3
Render: Real
Ask: Yes
Functions: None
WindowBounds: 242 44 914 789
Options: -b1024 -A -s -m7 -K -R


ioView background {0, 3818, 65535}
ioListing {7, 3} {374, 642}
ioCheckbox {438, 69} {30, 30} off checkbex1
ioCheckbox {439, 108} {30, 30} off checkbex2
ioCheckbox {440, 144} {30, 30} off checkbex3
ioCheckbox {441, 180} {30, 30} off checkbex4


-David