home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
code
/
c_sqwave.sit
< prev
next >
Wrap
Text File
|
1988-06-20
|
7KB
|
374 lines
18-Jun-88 14:44:16-MDT,6888;000000000000
Return-Path: <u-lchoqu%sunset@cs.utah.edu>
Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:44:06 MDT
Received: by cs.utah.edu (5.54/utah-2.0-cs)
id AA22658; Sat, 18 Jun 88 14:44:07 MDT
Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
id AA24794; Sat, 18 Jun 88 14:44:04 MDT
Date: Sat, 18 Jun 88 14:44:04 MDT
From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
Message-Id: <8806182044.AA24794@sunset.utah.edu>
To: rthum@simtel20.arpa
Subject: SquareWaveSound.c
/*
Square Wave Sound
*/
# include <qd.h>
# include <qdvars.h>
# include <event.h>
# include <toolbox.h>
# include <menu.h>
# include <event.h>
# include <sound.h>
# include <win.h>
# include <dialog.h>
# define TRUE 1
# define FALSE 0
swsynthptr myswptr ;
ptr myptr, dstorage ;
handle myhandle, itemhandle ;
int lp, soundlength = 226, program = TRUE, itemhit, itemtype ;
menuhandle applemenu, soundmenu ;
eventrecord event ;
windowptr soundwin, whichwin ;
windowrecord soundrec ;
rect rect1, utilrect ;
point mpoint ;
dialogptr apdialog ;
init ()
{
qdsetup () ;
windowsetup () ;
menusetup () ;
eventsetup () ;
dasetup () ;
}
qdsetup ()
{
initgraf ( &theport ) ;
initcursor () ;
}
dasetup ()
{
initdialogs () ;
teinit () ;
}
eventsetup ()
{
flushevents ( everyevent, 0 ) ;
}
windowsetup ()
{
initwindows () ;
setrect ( &rect1, 20, 35, 493, 323 ) ;
soundwin = newwindow ( &soundrec, &rect1, "Sound", TRUE, altdboxproc,
(long) 0, FALSE, (long) 1) ;
setrect ( &rect1, 0, 0, 473, 288 ) ;
setport ( soundwin ) ;
}
menusetup ()
{
static char apple[2] = { '\024', '\000' } ;
initmenus () ;
initfonts () ;
applemenu = newmenu ( 1, apple ) ;
soundmenu = newmenu ( 2, "Sound" ) ;
appendmenu ( applemenu, "About Sound...^1" ) ;
appendmenu ( soundmenu,
"Make Sound/S;Modify Sound/C;Repeat-Modify/R;Stop Sound/X;(-;Quit/Q" ) ;
insertmenu ( applemenu, 0) ;
insertmenu ( soundmenu, 0) ;
drawmenubar () ;
}
dallpurp ( dlgid ) /* general purpose dialog opener and bolder of item 1 */
int dlgid ;
{
apdialog = getnewdialog ( dlgid, dstorage, -1L ) ;
getditem ( apdialog, 1, &itemtype, &itemhandle, &utilrect ) ;
setport ( apdialog ) ;
pensize ( 3, 3 ) ; /* draw 'default' border */
insetrect ( &utilrect, -4, -4 ) ;
frameroundrect ( &utilrect, 16, 16 ) ;
modaldialog ( 0L, &itemhit ) ;
closedialog ( apdialog ) ;
setport ( soundwin ) ;
}
doclick ()
{
switch ( findwindow ( &event.where, &whichwin ) )
{
case inmenubar :
domenu ( menuselect ( &event.where ) ) ;
break ;
}
}
domenu (menuitem)
long int menuitem ;
{
int menu, item ;
menu = hiword ( menuitem ) ;
item = loword ( menuitem ) ;
switch ( menu )
{
case 1 : /* apple menu */
domenu1 ( item ) ;
break ;
case 2 : /* file menu */
domenu2 ( item ) ;
break ;
}
hilitemenu ( 0 ) ;
}
domenu1 (item)
int item ;
{
int a, b ;
switch ( item )
{
case 1 : /* About Sound */
dallpurp ( 1 ) ;
drawwindow () ;
break ;
}
}
domenu2 (item)
int item ;
{
switch ( item )
{
case 1 :
stopsound () ;
startsound ( myptr, 1362L, 0L ) ;
break ;
case 2 :
/*setcursor ( cross ) ;*/
do
{
getmouse ( &mpoint ) ;
newpoint () ;
}
while ( ! button () ) ;
/*setcursor ( arrow ) ;*/
domenu2 ( 1 ) ;
break ;
case 3 :
/*setcursor ( cross ) ;*/
stopsound () ;
startsound ( myptr, 1362L, 0L ) ;
do
{
if ( sounddone () )
startsound ( myptr, 1362L, 0L ) ;
getmouse ( &mpoint ) ;
newpoint () ;
}
while ( ! button () ) ;
/*setcursor ( arrow ) ;*/
break ;
case 4 :
stopsound () ;
break ;
case 6 :
stopsound () ;
program = FALSE ;
break ;
}
}
newpoint ()
{
int h, v, holder ;
point m1point ;
if ( mpoint != m1point )
{
m1point.a.h = mpoint.a.h ;
m1point.a.v = mpoint.a.v ;
h = mpoint.a.h / 2 * 2 ;
v = ( mpoint.a.v - 10 ) * 50 + 300 ;
lp = ( mpoint.a.h - 10 ) / 2 ;
if ( mpoint.a.v > 10 && mpoint.a.v < 278
&& mpoint.a.h > 10 && mpoint.a.h < 464 )
{
holder =
( myswptr->triplets[lp].count - 300 ) / 50 + 10 ;
if ( mpoint.a.v < holder )
{
penpat ( black ) ;
moveto ( h, holder ) ;
line ( 0, mpoint.a.v - holder ) ;
}
else if ( mpoint.a.v > holder )
{
penpat ( white ) ;
moveto ( h, mpoint.a.v - 1 ) ;
lineto ( h, 10 ) ;
}
myswptr->triplets[lp].count = v ;
}
}
}
setupsound ()
{
myhandle = newhandle ( 5000L ) ;
hlock ( myhandle ) ;
myptr = *myhandle ;
myswptr = ( swsynthptr ) myptr ;
myswptr->mode = swmode ;
for ( lp = 0 ; lp <= soundlength ; ++lp )
{
myswptr->triplets[lp].count = 300 + lp * 50 ;
myswptr->triplets[lp].amplitude = 120 ;
myswptr->triplets[lp].duration = 1 ;
}
myswptr->triplets[lp].count = 0 ;
myswptr->triplets[lp].amplitude = 0 ;
myswptr->triplets[lp].duration = 0 ;
}
drawwindow ()
{
int h = 10 ;
penpat ( gray ) ;
pensize ( 8, 268 ) ;
moveto ( 1, 10 ) ;
line ( 0, 0 ) ;
moveto ( 464, 10 ) ;
line ( 0, 0 ) ;
pensize ( 453, 8 ) ;
moveto ( 10, 1 ) ;
line ( 0, 0 ) ;
moveto ( 10, 279 ) ;
line ( 0, 0 ) ;
pensize ( 8, 8 ) ;
penpat ( black ) ;
moveto ( 1, 1 ) ;
line ( 0, 0 ) ;
moveto ( 464, 1 ) ;
line ( 0, 0 ) ;
moveto ( 1, 279 ) ;
line ( 0, 0 ) ;
moveto ( 464, 279 ) ;
line ( 0, 0 ) ;
pensize ( 1, 1 ) ;
for ( lp = 0 ; lp <= soundlength ; ++lp, h += 2 )
{
moveto ( h, ( myswptr->triplets[lp].count - 300 ) / 50 + 10 ) ;
lineto ( h, 277 ) ;
}
}
main ()
{
init () ;
setupsound () ;
drawwindow () ;
/*cross = getcursor ( 2 ) ;*/
while ( program )
{
getnextevent ( everyevent, &event ) ;
switch ( event.what )
{
case mousedown :
doclick () ;
break ;
case keydown :
if ( event.modifiers && cmdkey )
domenu ( menukey ( (char) ( loword ( event.message ) ) ) ) ;
break ;
}
}
hunlock ( myhandle ) ;
}