Click here to load reader
Upload
jghudson
View
214
Download
0
Embed Size (px)
Citation preview
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 1/16
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 2/16
can specify the name of
the argument you are changing followed by a colon and the value.
Keywords can be found in
the documentation files. The documentation for SinOsc.ar shows:
SinOsc.ar(freq, phase, mul,
add). The keywords are freq, phase, mul, and add. Using keywords
not only allows you to
enter a single argument out of order, but to mix the order of the
arguments. Here are several
versions of the SinOsc example written using keywords. All of them
have precisely the same
meaning.
keywords*/
({SinOsc.ar(freq: 44! p"ase: ! #ul: .4! add: )}.play$)
({SinOsc.ar(p"ase: ! freq: 44! add: ! #ul: .4)}.play$
)
({SinOsc.ar(freq: 44! #ul: .4)}.play$)
/*
Another good reason for using keywords is clarity. The keyword
provides a short explanation
of what each value means, like a short comment.
The last reason for using keywords is portability. Earlier I said it is
important to understand
that argument lists are not interchangeable. Consider these two lines:
Saw.ar(100, 500, 600)
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 3/16
and SinOsc.ar(100, 500, 600). The arguments for Saw are freq, mul,
and add. But for SinOsc
they are freq, phase, mul, and add. So the two lists are not
interchangeable. I can certainly use
100, 500, and 600 as arguments for the SinOsc, but they don't mean
the same thing as
they did with the Saw. A phase of 500 makes no sense, and a mul of
600 without an add will
produce negative values, probably not what I want.
But if I use keywords (and provided the two Ugens have the same
keywords), then I canswap the objects: SinOsc.ar(freq: 100, mul: 500, add: 1000) and
Saw.ar(freq: 100, mul: 500,
add: 1000) will have a similar effect in a patch. Warning: this can be
either dangerous or a
source of serendipity. You should always double check the keywords
and understand what
they mean in a patch. If a keyword is incorrect it is ignored, but you
do get a warning posted
to the post window.
*/
({
SinOsc.ar(freq: SinOsc.ar(
freq: %&!
add: &!#ul: '
)!add: !#ul: .4!p"ase:
)}.play
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 4/16
)
/*
MouseX.kr and MouseY.kr - MouseButton
In the examples above we changed each value, then ran the code,
then changed the value and
ran the example again. You may have wished you could attach some
type of knob to the
patch so that you could try a range of values at once. This is what
MouseX.kr and MouseY.kr
will do. They link mouse movement and position to values that can be
used in the patch. Thefirst three arguments are: minval, maxval, warp.
These ugens can replace any static value with a range of values that
change in real time in
relation to the position of the mouse on the screen. As an illustration,
try the first patch
reproduced below with a MouseX in place of the first argument for
LFNoise0.
ouse (+,oise! SinOsc! #ul)*/
({SinOsc.ar(+,oise.ar
(ouse.kr(%! &)! &! -)! #ul: .&)}.play$)
//dd ouse to t"e add ar0u#ent
({SinOsc.ar(+,oise.ar
(ouse.kr(%! &)! &! ouse.kr(&! %))! #ul: .&)}.play$)
/*
If you want to see the values that the mouse is triggering, send the
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 5/16
message.poll and the values will
appear in the post window.
*/
({SinOsc.ar(+,oise.ar
(ouse.kr(%! &).poll! &! ouse.kr(&! %).poll)! #ul: .&)}.play$)
/*
Much easier than changing, trying, changing, trying, etc.
In the example below MouseY (Y axis is top to bottom) is used to
control amplitude. The
minval is 0.9 and maxval is 0.0. These may seem backwards, but the
minimum position for
the mouse is actually the top of the screen, the maximum is the
bottom, and it makes more
sense to me to have the top of the screen 0.9. The next example
adds a MouseX to control
frequency. The minimum value is A 220 and the maximum is twooctaves higher, or 880.
Since the motion of the mouse spans two octaves you might be able
to play a tune using the
mouse to find each pitch. First try an octave, then a fifth, then a scale.
See if you can play a
simple tune, such as Mary Had a Little Lamb.
ouse controllin0 a#p and freq
*/({SinOsc.ar(44! #ul: ouse.kr(.1! ))}.scope$)
({SinOsc.ar(ouse.kr(''! 22)! #ul: .3)}.scope$)
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 6/16
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 7/16
for exponential. Try playing a melody or major scale with the following
adjustments. You
will notice that with an exponential warp the whole and half-steps
seem to be the same
distance all across the screen.
eponential c"an0e*/
({SinOsc.ar(ouse.kr(''! 22)! #ul: .3)}.play$)
(
{SinOsc.ar(ouse.kr(''! 22! 5eponential5)! #ul: .3)}.play$)
/*
As a general rule you will want to use exponential values when
dealing with frequency.
I introduce MouseX and Y as a tool for trying values in patches and
experimenting in real
time, but it is reminiscent of one of the earliest (and very successful)
electronic instruments;
the Theremin. The Theremin controlled pitch and amplitude by
proximity of the performer's
hand to an antenna and protruding loop. Performers "played" the
Theremin by moving their
hands closer or farther away from the antenna or loop.
Below is a virtual Theremin with controls connected to mouse position: up
and down for
pitch, left and right for amplitude. You can practically see the spaceship
door opening:
6laatu 7arada nikto8
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 8/16
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 9/16
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 10/16
frequency.
Fortunately there is a method for generating the frequency of an
equal tempered scale by way
of MIDI. SC understands MIDI numbers, and can convert them to
frequency. By way of
review; the MIDI number for C4 is 60, and each half-step is 1. To
convert these to frequency,
use the midicps message.
?&@! &2! &1! -! -%! -'! -3! -4! -&! --! -@! -2! -1! @!@%A.#idicps.round(.%)$
Now back to the original MouseX control patch, with even more
confusion. We can now
express the two octave range using the MIDI numbers 57 (A3, or 220
Hz) to 81 (A5, or 880
Hz). But wait, are you a step ahead of me? Do you use a linear warp,
or exponential warp? In
this case, linear, because MIDI values are linear. That is to say the
difference between thefirst octave (57 to 59) is the same as the second (59 to 81): 12.
The first version of this improved patch appears to have correct
tracking with pitches, but the
values are not discrete. That is because the MouseX will still return
fractions, that is values
between the MIDI pitches, such as 62.1453 or 74.874. To force them
to be discrete, we add
the round message, which rounds them to 1. (Try 0.5 and 2.0 for
quarter tone and whole tone
scales).
*/
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 11/16
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 12/16
"ert!.%)
}))
//say o#...
(// #odal space// #ouse controls discrete pitc" in dorian #odear scale! 7uBer$scale ; +loatrray?! '! 3.'! &! @! 1! %A$ // dorian scale7uBer ; CuBer.alloc(s! scale.sie!%! {E7E 7.setns0(! scale) })$
({ar #i$
#i ;
// lead toneSinOsc.ar(
(De0ree9o6ey.kr(
7uBer.7ufnu#!ouse.kr(!%&)! // #ouse indees into scale%'! // %' notes per octae%! // #ul ; %@' // oBset 7y @' notes
)F +,oise%.kr(?3!3A! .4) // add so#e low freq stereo detunin0
).#idicps! // conert #idi notes to"ert
!.%)
// drone &t"sF GH+.ar(+Hulse.ar(?42!&&A.#idicps! .%&)!
SinOsc.kr(.%! ! %! @').#idicps! .%! .%)$
// add so#e @5s euro=space=rock ec"oIo#7,.ar(#i! .3%! .3%! '! %! #i)
}.play))
/*
MouseButton
You can also use MouseButton.kr to control parameters in a patch. The
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 13/16
arguments are: minval, maxval, lag
(Use the left button)
*/
{SinOsc.ar(ouseCutton.kr(4! %-! .%)! ! .%) }.play$
{SinOsc.ar(ouseCutton.kr(4! @4! ')! ! .%) }.play$
({SinOsc.ar(+,oise.ar(ouseCutton.kr(%! &! &)! &! -)! #ul: .&)}.play$)
/*There are other methods for linking an external control to a value in a
patch. You can use
TabletX, TabletY, and TabletZ if you have a Wacom input device. You
can also link controls
to an external MIDI control surface or keyboard. You can attach
actions to the computer
keyboard (keystate) or build a GUI with sliders and buttons. The code
required for each of
these methods is a bit too involved for this section of the text. For now
I would like to focus
on internal automatic controls.
MORE FUN!
*************************************************************************
The patch below uses only two SinOsc and one LFNoise0, but can
generate very rich sounds
because of the way they are linked together (frequency modulation,
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 14/16
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 15/16
(// eponential rando#{i.>ll(%'! // nu#7er of oscillators{ar0 i$
Han'.ar(SinOsc.ar(SinOsc.ar(freq: ouse.kr(rrand(.%! &.)! rrand(3.! '.))! // speed of i7rato#ul: ouse.kr(%! &)! // widt" of i7ratoadd: eprand('! &))! // freq of oscillators#ul: #a(! +,oise.kr(ouse.kr(rrand(%! -)! rrand(-! %)))))!
%..rand')})*.3}.play)
(
// linear rando# waes{i.>ll(%'! // nu#7er of oscillators{ar0 i$Han'.ar(SinOsc.ar(SinOsc.ar(
freq: ouse.kr(rrand(.%! &.)! rrand(3.! '.))! // speed of i7rato#ul: ouse.kr(%! &)! // widt" of i7ratoadd: rrand('! &))! // freq of oscillators#ul: #a(! +,oise.kr(ouse.kr(rrand(%! -)! rrand(-! %)))))!
%..rand')})*.3}.play
)
/*
Jen ore +un8
Hractice wit" t"e patc"es we "ae used so far as well as t"eea#ples 7elow. dd #ouse controls to arious ar0u#entsand see w"at "appens. Jplore t"e "elp >les for t"e KLensyou aren5t fa#iliar wit". 9ry recordin0 to t"e "ard drie andopen your sound >le in udacity and pro9ools.*/
(// #oto re
8/9/2019 Tutorial 4KeyWords Mouse
http://slidepdf.com/reader/full/tutorial-4keywords-mouse 16/16