Skip to content

Commit

Permalink
Documentation: Creating Examples
Browse files Browse the repository at this point in the history
Created examples for:
MouseDown()
MouseX()
MouseY()
ASREnvelope()
Line()
Impulse()
ClockDivider()
Sequence()

And fixing a typo in BufferPlayer().
  • Loading branch information
gregwht committed Jan 26, 2024
1 parent 0825eb8 commit 64c18a7
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 4 deletions.
11 changes: 11 additions & 0 deletions docs/library/control/mousedown/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# When the left mouse button is clicked, as detected by MouseDown(), an LFO is applied to the oscillator's frequency.
#-------------------------------------------------------------------------------
lfo = SineLFO(5, 100, 600)
frequency = If(MouseDown(), lfo, 100)
osc = TriangleOscillator(frequency)
osc.play()
graph.wait()
13 changes: 13 additions & 0 deletions docs/library/control/mousedown/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# A simple wobbling synthesiser controlled using the mouse. When the mouse is clicked, as detected by MouseDown(), an LFO is activated and affects the oscillator's frequency. MouseX position changes the rate of the LFO. MouseY position changes the upper frequency limit, affecting pitch.
#-------------------------------------------------------------------------------
rate = MouseX() * 10
upper_limit = MouseY() * 1500
lfo = SineLFO(rate, 100, upper_limit)
frequency = If(MouseDown(), lfo, 100)
osc = TriangleOscillator(frequency)
osc.play()
graph.wait()
11 changes: 11 additions & 0 deletions docs/library/control/mousex/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using the MouseX position to change the rate of an LFO, which is modulating an oscillator's frequency
#-------------------------------------------------------------------------------
lfo_rate = MouseX() * 10
frequency = SineLFO(lfo_rate, 100, 600)
osc = TriangleOscillator(frequency)
osc.play()
graph.wait()
13 changes: 13 additions & 0 deletions docs/library/control/mousex/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# A simple wobbling synthesiser controlled using the mouse. When the mouse is clicked, as detected by MouseDown(), an LFO is activated and affects the oscillator's frequency. MouseX position changes the rate of the LFO. MouseY position changes the upper frequency limit, affecting pitch.
#-------------------------------------------------------------------------------
rate = MouseX() * 10
upper_limit = MouseY() * 1500
lfo = SineLFO(rate, 100, upper_limit)
frequency = If(MouseDown(), lfo, 100)
osc = TriangleOscillator(frequency)
osc.play()
graph.wait()
10 changes: 10 additions & 0 deletions docs/library/control/mousey/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using the MouseY position to change the frequency of an oscillator.
#-------------------------------------------------------------------------------
frequency = MouseY() * 1000
osc = TriangleOscillator(frequency)
osc.play()
graph.wait()
13 changes: 13 additions & 0 deletions docs/library/control/mousey/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# A simple wobbling synthesiser controlled using the mouse. When the mouse is clicked, as detected by MouseDown(), an LFO is activated and affects the oscillator's frequency. MouseX position changes the rate of the LFO. MouseY position changes the upper frequency limit, affecting pitch.
#-------------------------------------------------------------------------------
rate = MouseX() * 10
upper_limit = MouseY() * 1500
lfo = SineLFO(rate, 100, upper_limit)
frequency = If(MouseDown(), lfo, 100)
osc = TriangleOscillator(frequency)
osc.play()
graph.wait()
11 changes: 11 additions & 0 deletions docs/library/envelope/asrenvelope/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using an ASR Envelope to shape a square wave oscillator
#-------------------------------------------------------------------------------
osc = SquareOscillator(500)
envelope = ASREnvelope(0.1, 0.0, 0.5)
output = osc * envelope
output.play()
graph.wait()
12 changes: 12 additions & 0 deletions docs/library/envelope/line/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using a line to control the gain of an oscillator, emulating a sidechain ducking effect.
#-------------------------------------------------------------------------------
clock = Impulse(frequency=1.0)
line = Line(0.0, 0.5, 1.0, 0, clock)
osc = SawOscillator(200)
output = osc * line
output.play()
graph.wait()
8 changes: 5 additions & 3 deletions docs/library/oscillators/impulse/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Impulse generator producing an impulse every second (60bpm)
# Using an Impulse node as a clock to trigger an envelope once per second.
#-------------------------------------------------------------------------------
impulse = Impulse(frequency=1.0)
output = impulse * 0.5
clock = Impulse(1.0)
osc = TriangleOscillator(250)
envelope = ASREnvelope(0.01, 0.0, 0.5, 1.0, clock)
output = osc * envelope
output.play()
graph.wait()
23 changes: 23 additions & 0 deletions docs/library/sequencing/clockdivider/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using a ClockDivider to create rhythms related to the main clock. Here the oscillator in the left channel is heard on every tick of the clock. The oscillator in the right channel is heard every 3 ticks of the clock.
#-------------------------------------------------------------------------------
clock = Impulse(2.0)
divided_clock = ClockDivider(clock, 3)

oscillator_a = TriangleOscillator(220)
oscillator_b = TriangleOscillator(440)

envelope_a = ASREnvelope(0.01, 0.0, 0.25, 1.0, clock)
envelope_b = ASREnvelope(0.01, 0.0, 0.5, 1.0, divided_clock)

voice_a = oscillator_a * envelope_a
voice_b = oscillator_b * envelope_b

left = StereoPanner(voice_a, -1.0)
right = StereoPanner(voice_b, 1.0)

left.play()
right.play()
12 changes: 12 additions & 0 deletions docs/library/sequencing/sequence/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Creating a sequence using the MIDI note values of a C Major scale, starting on middle C.
#-------------------------------------------------------------------------------
clock = Impulse(2.0)
sequence = Sequence([ 60, 62, 64, 65, 67, 69, 71, 72 ], clock)
frequency = MidiNoteToFrequency(sequence)
oscillator = TriangleOscillator(frequency)
oscillator.play()
graph.wait()
2 changes: 1 addition & 1 deletion source/include/signalflow/node/buffer/buffer-player.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace signalflow

/**--------------------------------------------------------------------------------*
* Plays the contents of the given buffer. start_time/end_time are in seconds.
* When a clock signal is receives, rewinds to the start_time.
* When a clock signal is received, rewinds to the start_time.
*---------------------------------------------------------------------------------*/
class BufferPlayer : public Node
{
Expand Down

0 comments on commit 64c18a7

Please sign in to comment.