### Launch FoxDot Editor via Command Line Source: https://foxdot.org/docs/index This command launches the FoxDot interactive editor from the command line using Python. It requires Python to be installed and the FoxDot module to be accessible in your environment's PATH. ```bash $ python -m FoxDot ``` -------------------------------- ### Start FoxDot in SuperCollider Source: https://foxdot.org/docs/index This code snippet initializes FoxDot within the SuperCollider environment, allowing SuperCollider to receive and process musical messages from FoxDot. Ensure SuperCollider is open before executing. ```supercollider FoxDot.start ``` -------------------------------- ### Python: PRand Generator Examples Source: https://foxdot.org/docs/pattern-generators Provides examples of initializing and using the `PRand` generator in Python. It covers generating random integers within a specified range (`lo`, `hi`), generating random integers from 0 to `lo` if `hi` is omitted, and picking random values from a provided list. ```python >>> PRand(5, 10)[:10] P[9, 10, 7, 10, 5, 10, 6, 5, 5, 7] >>> PRand(5)[:10] P[5, 4, 5, 5, 4, 1, 5, 5, 2, 0] >>> PRand([1, 2, 3])[:10] P[3, 2, 2, 2, 1, 3, 3, 2, 2, 1] ``` -------------------------------- ### Send MIDI Notes with MidiOut Synth Source: https://foxdot.org/docs/setting-up-midi This example shows how to use the MidiOut synth in FoxDot to send MIDI pitch and amplitude messages to a selected device. It illustrates basic note sequencing and rhythmic variations like 'stutter'. ```python p1 >> MidiOut([0,1,2,3,4,5], dur=PDur(3,8), amp=[1,1/2,1/2]).every(6, "stutter", 4, dur=3, oct=6) ``` -------------------------------- ### Basic FoxDot play synth usage Source: https://foxdot.org/docs/playing-samples Demonstrates the fundamental usage of the 'play' synth in FoxDot. The first argument is a string where characters map to specific audio samples. This example shows a basic disco drum beat. ```python p1 >> play("x-o-") ``` -------------------------------- ### Python: PxRand Generator Examples Source: https://foxdot.org/docs/pattern-generators Demonstrates the usage of the `PxRand` generator in Python, which is similar to `PRand` but guarantees that elements will not be repeated within the generated sequence. Examples show its application with a numerical range and with a list of values. ```python >>> PxRand(5, 10)[:10] P[6, 10, 8, 6, 9, 6, 9, 6, 10, 7] >>> PxRand(5)[:10] P[4, 3, 2, 1, 4, 1, 0, 5, 2, 3] >>> PxRand([1, 2, 3])[:10] P[2, 3, 2, 1, 3, 2, 3, 1, 3, 2] ``` -------------------------------- ### Create Chords in FoxDot Source: https://foxdot.org/docs/player-object-intro Shows how to create chords in FoxDot by using a tuple instead of a list for the chord definition. This example adds a basic triad to each note played by the 'pluck' synth. ```python p1 >> pluck([0, 1, 2, 3], dur=2) + (0, 2, 4) ``` -------------------------------- ### Example FoxDot OSC Note Message Source: https://foxdot.org/docs/sending-osc-messages Provides a concrete example of an OSC message for triggering a 'pluck' synth in SuperCollider, specifying parameters like frequency, amplitude, panning, and sustain. ```foxdot ["/s_new", "pluck", 1001, 1, 0, "freq", 440, "amp", 1, "pan", -1, "sus", 1] ``` -------------------------------- ### Alternate Sounds in FoxDot Sample Sequence Source: https://foxdot.org/docs/player-object-intro Uses round brackets within the 'play' SynthDef string to alternate between different sounds on each loop of the sequence. This example alternates between 'x-' and '-x' before playing 'o-'. ```python d1 >> play("(x-)(-x)o-") ``` -------------------------------- ### FoxDot Pattern Transformation Examples Source: https://foxdot.org/docs/pattern-basics Illustrates how to perform mathematical transformations on FoxDot Patterns, including addition with lists or other Patterns, and using built-in methods like rotate, reverse, and sort. ```python >>> P[0, 1, 2, 3] + P[4, 5, -2] P[4, 6, 0, 7, 5, -1, 6, 8, -2, 5, 7, 1] >>> P[4, 1, 3, 2].rotate() P[1, 3, 2, 4] >>> P[4, 1, 3, 2].reverse() P[2, 3, 1, 4] >>> P[4, 1, 3, 2].sort() P[1, 2, 3, 4] ``` -------------------------------- ### Offsetting TimeVar Start Time Source: https://foxdot.org/docs/timevar-advanced Demonstrates how to offset the start time of a TimeVar sequence using the 'start' keyword. This allows for precise control over when a sequence begins, independent of the bar structure. It can be combined with singletons like 'now' for immediate effect. ```python # Original chord sequence var([0, 4, 5, 3], 4) # Update value after 1 beat of the bar var([3, 0, 4, 5, 3], [1, 4, 4, 4, 3]) # Offset start time by 1 beat var([0, 4, 5, 3], start=1) # Ramp amplitude from 0 to 1 over 8 beats, starting now d1 >> play("x-o-", amp=linvar([0, 1], 8, start=now)) ``` -------------------------------- ### FoxDot PGroup Lacing Examples Source: https://foxdot.org/docs/pgroups Illustrates how lists or Patterns within PGroups create sequences of PGroups. This 'lacing' behavior allows for complex rhythmic patterns by combining different value sequences. ```python # Lacing a PGroup >>> print(P(0, 1, [2, 3])) P[P(0, 1, 2), P(0, 1, 3)] # Lacing a PGroup within a Pattern >>> print(P[0, 1, P(2, 3, [4, 5])]) P[0, 1, P[P(2, 3, 4), P(2, 3, 5)]] # Lacing a PGroup with multiple lists >>> print(P(0, [1, 2], [3, 4, 5])) P[P(0, 1, 3), P(0, 2, 4), P(0, 1, 5), P(0, 2, 3), P(0, 1, 4), P(0, 2, 5)] ``` -------------------------------- ### Apply Low-Pass Filter with Resonance Source: https://foxdot.org/docs/player-effects Demonstrates setting the low-pass filter cutoff and adjusting resonance using the `lpf` and `lpr` keywords. It also shows how to use `linvar` to vary these parameters over time. Requires no external installations. ```python # Set the low pass filter cutoff to 400 Hz d1 >> play("x-o-", lpf=400) # Changing the resonance - can you hear the difference? d1 >> play("x-o-", lpf=400, lpr=0.2) # Use a linvar to vary both values over time d1 >> play("x-o-", lpf=linvar([500,5000],32), lpr=linvar([1,0.1],28)) ``` -------------------------------- ### Python: PwRand Generator Examples Source: https://foxdot.org/docs/pattern-generators Illustrates the functionality of the `PwRand` generator in Python, which allows for weighted random selection. It takes a list of values and a corresponding list of weights, enabling items with higher weights to be picked more frequently. Examples show its use with different value and weight combinations. ```python >>> PwRand([0, 1], [1, 2])[:10] P[1, 0, 0, 1, 1, 1, 1, 0, 1, 1] >>> PwRand([0, 1, 2], [1, 2, 3])[:10] P[1, 2, 2, 2, 2, 2, 0, 2, 2, 1] ``` -------------------------------- ### FoxDot: Gradual Change TimeVar Usage Examples Source: https://foxdot.org/docs/different-types-of-timevar Provides practical examples of using gradual-change TimeVars (linvar, expvar) in FoxDot for controlling parameters like high-pass filter frequency. It shows how to achieve both continuous ramps and abrupt resets by manipulating durations. ```python # No gradual change in the high pass frequency p1 >> dirt(dur=4, hpf=linvar([0, 4000], 4)) # Apparent gradual change in the high-pass frequency p2 >> dirt(dur=1/4, hpf=linvar([0, 4000], 4)) # Ramp up to 4000Hz then reset to 0 p1 >> dirt(dur=1/4, hpf=expvar([0, 4000], [8, 0])) # Use a regular TimeVar to set the value to 0 for 28 beats p1 >> dirt(dur=1/4, hpf=var([0, expvar([0, 4000], [4, 0])], [28, 4])) ``` -------------------------------- ### Play Successive Samples in FoxDot Step Source: https://foxdot.org/docs/player-object-intro Uses square brackets within the 'play' SynthDef string to play multiple characters successively within the space of a single step. This example plays a triplet of hi-hats during its fourth step. ```python d1 >> play("x-o[---]", dur=1) ``` -------------------------------- ### Add Pitch Variation to FoxDot Sequence Source: https://foxdot.org/docs/player-object-intro This example demonstrates adding variation to a FoxDot sequence by playing every 3rd note 4 pitches higher. It combines a sequence of pitches and durations with an added pitch offset. ```python p1 >> pluck([0, 1, 2, 3], dur=2) + [0, 0, 4] ``` -------------------------------- ### Get Available Player Attributes (Python) Source: https://foxdot.org/docs/player-attributes Retrieves a tuple of all available keyword arguments for FoxDot player objects. This is useful for understanding the full range of configurable parameters for sound manipulation. ```python print(Player.get_attributes()) ``` -------------------------------- ### Random Sample Selection in FoxDot Source: https://foxdot.org/docs/player-object-intro Employs curly braces within the 'play' SynthDef string to select a sound at random from the specified characters, adding variety to the sequence. This example randomly picks from 'x', '=', '*', or '-'. ```python d1 >> play("x-o{-= *}") ``` -------------------------------- ### FoxDot TempoClock: Getting Beat and Time Information Source: https://foxdot.org/docs/using-the-tempoclock These methods retrieve information about the current state of the TempoClock, such as the current beat, bar length, and conversions between beats and seconds. They are useful for precise timing and synchronization within FoxDot. ```python # Returns the beat at the start of the next 16 beat cycle Clock.mod(16) # Returns the beat at the start of the next 4 bar cycle Clock.mod(Clock.bars(4)) ``` -------------------------------- ### Schedule Pattern Method 'offadd' with Arguments Source: https://foxdot.org/docs/algorithmic-manipulation This snippet shows how to schedule the 'offadd' method, which layers a pattern with itself, adding a value and delaying by a duration. The 'offadd' method takes two arguments: the value to add and the delay time. This example illustrates its use with the 'every' function for musical effects. ```python # Play a note 2 steps higher delayed 1/2 a beat p1 >> pasha([0, 4], dur=[3/4, 3/4, 1/2]).every(3, "offadd", 2) # Play a note 4 steps higher delayed 3/4 of a beat p1 >> pasha([0,1,3,4], dur=1/2).every(5, "offadd", 4, 3/4) ``` -------------------------------- ### Play Notes with Pitch, Duration, and Amplitude in FoxDot Source: https://foxdot.org/docs/player-object-intro Assigns a sequence of notes (pitches), durations, and amplitudes to a FoxDot player object. The pitches are based on the C-Major scale indices. This example plays three notes in sequence until the player is stopped. ```python p1 >> pluck([0, 2, 4], dur=[1, 1/2, 1/2], amp=0.75) ``` -------------------------------- ### Apply Wave-Shape Distortion Source: https://foxdot.org/docs/player-effects Introduces wave-shape distortion by altering the waveform's shape. Controlled by the `shape` keyword (0-1, larger values accepted). Does not require extra installation. Affects both sample and synth players. ```python # Add distortion to both sample and synth players d1 >> play("x * ", shape=0.5) p1 >> dirt([0,5], shape=0.5, dur=8) + (0,4) ``` -------------------------------- ### Python: PRand Mathematical Operations Source: https://foxdot.org/docs/pattern-generators Shows how to perform basic mathematical operations directly on PRand generator objects. The example demonstrates multiplying a PRand generator by a scalar value, resulting in a new PRand generator that reflects the operation. Slicing the transformed generator reveals the modified sequence of values. ```python >>> my_gen2 = my_gen * 2 >>> print(my_gen2) PRand(Mul 2) >>> my_gen2[:10] P[8, 12, 2, 16, 6, 16, 16, 16, 0, 2] ``` -------------------------------- ### Play a Pluck Sound Loop in FoxDot Source: https://foxdot.org/docs/index This Python code snippet within the FoxDot editor plays a continuous loop of a single plucked note. The note will play until explicitly stopped or the script is terminated. ```python p1 >> pluck() ``` -------------------------------- ### Select Specific MIDI Device with FoxDot Source: https://foxdot.org/docs/setting-up-midi This code snippet demonstrates how to select a specific MIDI device for FoxDot to use by providing its index. This is useful when multiple MIDI devices are connected and you need to target a particular one. ```python FoxDot.midi(1) ``` -------------------------------- ### Exponential Value Change with expvar in FoxDot Source: https://foxdot.org/docs/different-types-of-timevar Demonstrates the expvar TimeVar in FoxDot, which exhibits exponential change between values. The example highlights how the change starts slow and accelerates, with decreasing values showing the reverse pattern. ```python >>> my_expvar([0, 1], 4) >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 1, 0.25, 0.38, 0.06 >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 2, 0.50, 0.71, 0.25 >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 3, 0.76, 0.93, 0.57 >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 4, 1, 1, 1 >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 5, 0.74, 0.92, 0.93 >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 6, 0.50, 0.71, 0.75 >>> print(Clock.now(), my_linvar, my_sinvar, my_expvar) 7, 0.25, 0.38, 0.43 ``` -------------------------------- ### Stop a Pluck Sound Loop in FoxDot Source: https://foxdot.org/docs/index This Python code snippet adds a stop command to an existing FoxDot loop, effectively halting the playback of the plucked note. This is used to cease ongoing musical patterns. ```python p1 >> pluck().stop() ``` -------------------------------- ### FoxDot PRange: Generate Sequential Number Patterns Source: https://foxdot.org/docs/pattern-functions PRange creates a Pattern of sequential numbers starting from 'start' and ending before 'stop', with an optional 'step' increment. If 'stop' is omitted, the series starts from 0 and ends at 'start'. This is ideal for creating scales or arpeggiated sequences. ```python >>> PRange(5) P[0, 1, 2, 3, 4] >>> PRange(2, 7) P[2, 3, 4, 5, 6] >>> PRange(4, 14, 2) P[4, 6, 8, 10, 12] ``` -------------------------------- ### FoxDot play synth sample keyword Source: https://foxdot.org/docs/playing-samples Demonstrates the 'sample' keyword argument in the 'play' synth to specify which sample file to use. It can be a single integer, a list, or a tuple for varied selection. ```python p1 >> play("x-o-", sample=1) p1 >> play("x-o-", sample=[0, 1, 2]) p1 >> play("x-o-", sample=(0, 3)) ``` -------------------------------- ### Print Available Synths in FoxDot Source: https://foxdot.org/docs/player-object-intro This code snippet prints a list of all available SynthDefs in FoxDot, allowing users to choose which instrument to assign to a player object. It is a fundamental step before assigning any sound to a player. ```python print(SynthDefs) ``` -------------------------------- ### FoxDot Playing Chords with PGroups Source: https://foxdot.org/docs/pattern-basics Shows how to use PGroups (created from tuples) within a FoxDot Pattern to play multiple notes simultaneously, effectively creating chords. ```python p1 >> pluck([(0, 2, 4), (0, 3, 5)], dur=4) ``` -------------------------------- ### Create Delta Sequences with PDelta Source: https://foxdot.org/docs/pattern-generators PDelta generates a numerical series by cumulatively adding values from a list of deltas. A single positive delta creates an infinite series. The starting point can be set with the 'start' parameter. ```python >>> PDelta([0.1, 0.5, -0.3])[:10] P[0, 0.1, 0.6, 0.3, 0.4, 0.9, 0.6, 0.7, 1.2, 0.9] ``` ```python >>> PDelta([0.5])[:10] P[0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5] ``` ```python >>> PDelta([0.5, -0.5], start=1)[:10] P[1, 1.5, 1.0, 1.5, 1.0, 1.5, 1.0, 1.5, 1.0, 1.5] ``` -------------------------------- ### Generate Random Walks with PWalk Source: https://foxdot.org/docs/pattern-generators PWalk creates a series of integers that move by a 'step' size, bounded by +/- 'max'. The series can start at a specific value using 'start'. It's useful for creating arpeggiated or meandering melodic lines. ```python >>> PWalk()[:10] P[0, 1, 2, 1, 2, 3, 2, 3, 4, 5] ``` ```python >>> PWalk(20, 5, 5)[:10] P[5, 10, 15, 20, 15, 20, 15, 20, 15, 20] ``` -------------------------------- ### Play Basic Drum Pattern with FoxDot Samples Source: https://foxdot.org/docs/player-object-intro Plays a basic drum pattern using the FoxDot 'play' SynthDef. It takes a string of characters, where each character represents a different percussion sound. ```python d1 >> play("x-o-") ``` -------------------------------- ### FoxDot PTri: Create Triangular Wave Patterns Source: https://foxdot.org/docs/pattern-functions PTri generates a Pattern that ascends from 'start' to 'stop' and then descends back, with an optional 'step' increment. If 'stop' is omitted, it peaks at 'start'. This function is useful for creating arpeggiated or oscillating melodic lines. ```python >>> PTri(5) P[0, 1, 2, 3, 4, 3, 2, 1] >>> PTri(2, 7) P[2, 3, 4, 5, 6, 5, 4, 3] >>> PTri(4, 14, 2) P[4, 6, 8, 10, 12, 10, 8, 6] ``` -------------------------------- ### Create Chord Sequence from Player Pitch Source: https://foxdot.org/docs/player-keys Demonstrates generating a chord sequence by adding intervals to the pitch of a source player. This allows for harmonically rich accompaniment. ```python p1 >> bass([0, 4, 5, 3], dur=4) p2 >> pluck(p1.pitch + (0, 2, 4), dur=1/2) ``` -------------------------------- ### Creating and Accessing FoxDot Patterns Source: https://foxdot.org/docs/pattern-basics Shows various ways to create FoxDot Pattern objects, including direct initialization with P[], using the Pattern class constructor, and accessing elements using modulo indexing. ```python my_pattern = P[0, 1, 2, 3] my_pattern = Pattern([0, 1, 2, 3]) >>> pat = P[0, 1, 2] >>> print(pat[2]) 2 >>> print(pat[3]) 0 ``` -------------------------------- ### FoxDot play synth layering sequences Source: https://foxdot.org/docs/playing-samples Illustrates how to layer multiple sequences simultaneously using angle brackets '<>' within a single 'play' synth call. This allows for complex polyrhythms and sound designs. ```python p1 >> play("< + + [ +]>") p1 >> play(P["x-o-"].zip(P[" + + [ +]"])) p1 >> play("< + + [ +]>", pan=(-1, 1)) p1 >> play("< + + [ +]>", sample=(2, 0)) p1 >> play("< + + [ +]>", sample=(2, 0)).every(4, "sample.offadd", 2) ``` -------------------------------- ### Left Trim Pattern Source: https://foxdot.org/docs/pattern-methods Removes items from the start of the pattern up to a specified 'size'. This is analogous to 'trim' but operates from the beginning of the pattern. ```python >>> print(P[1, 2, 3, 4, 5].ltrim(3)) P[3, 4, 5] ``` -------------------------------- ### Invert Player Amplitude Source: https://foxdot.org/docs/player-keys Explains how to invert the amplitude of a player based on a condition. This example uses a boolean expression to control when a second player produces sound. ```python p1 >> play("x-o-", amp=[1,1,0,1,0,1,0], dur=1/4) p2 >> play("*", amp=p1.amp != 1, dur=1/4) ``` -------------------------------- ### Synchronize MIDI and FoxDot Messages Source: https://foxdot.org/docs/setting-up-midi This code demonstrates how to synchronize MIDI messages with FoxDot events by adjusting the `Clock.midi_nudge` value. This compensates for potential timing discrepancies between the two systems, ensuring sounds play in sync. ```python p1 >> MidiOut([0,4]) p2 >> play("x * ") # Value is usually between 0.15 and 0.25 Clock.midi_nudge = 0.2 ``` -------------------------------- ### Set Single Note Duration (Python) Source: https://foxdot.org/docs/player-attributes Sets a uniform duration for all notes in a sequence using the 'dur' attribute. This example sets the duration to 1/2 beat for all notes played. ```python p1 >> pluck([0, 1, 2, 3], dur=1/2) ``` -------------------------------- ### FoxDot play synth with alternating samples Source: https://foxdot.org/docs/playing-samples Illustrates how to use round brackets in the 'play' synth sequence to alternate between different sounds on each loop. This allows for more dynamic patterns. ```python p1 >> play("(x-)(-x)o-") p1 >> play("(x-)(-(xo))o-") ``` -------------------------------- ### Accompany Root Note of Chord Sequence Source: https://foxdot.org/docs/player-keys Demonstrates using indexing to access the root note of a chord sequence generated by a player, and then applying the .accompany() method to create a bass line that follows the chord roots. ```python p1 >> pluck([0, 4, 5, 3], dur=4) + (0, 2, 4) p2 >> blip(p1.pitch[0].accompany()) ``` -------------------------------- ### Set Octave for Notes (Python) Source: https://foxdot.org/docs/player-attributes Demonstrates how to set the octave for played notes using the 'oct' attribute. This example plays notes across octaves 4, 5, and 6, affecting the pitch. ```python p1 >> pluck(oct=[4, 5, 6]) ``` -------------------------------- ### Play Audio Samples with FoxDot's 'play' Player Source: https://foxdot.org/docs/player-attributes Uses the 'play' player to trigger audio samples based on a 'play string'. The 'sample' keyword specifies which sample to play from a folder, allowing for custom sample selection. ```python # Default samples p1 >> play("x-o-") # A different set of samples p1 >> play("x-o-", sample=1) # Can be a list of values p1 >> play("x-o-", sample=[0, 1, 2]) ``` -------------------------------- ### Python Standard Loop with Time Sleep Source: https://foxdot.org/docs/temporal-recursion A standard Python example using `time.sleep(1)` to introduce a one-second delay in a loop. While it creates a timed execution, it lacks interactivity and cannot be easily modified during runtime. ```python import time for n in range(21): if 0 > n > 4: d1 >> play("x ") elif 4 > n > 20: d1 >> play("x-") else: d1.stop() time.sleep(1) ``` -------------------------------- ### FoxDot TempoClock: Synchronization Methods Source: https://foxdot.org/docs/using-the-tempoclock These methods enable synchronization of FoxDot with external applications or devices. `sync_to_espgrid` connects to EspGrid for cross-environment synchronization, `sync_to_midi` attempts MIDI clock synchronization (experimental), and `connect` allows network synchronization between FoxDot instances. ```python # Synchronise with EspGrid Clock.sync_to_espgrid(host="localhost", port=5510) # EXPERIMENTAL: Synchronise to an external MIDI device’s clock Clock.sync_to_midi(sync=True) # Connect to a master FoxDot instance over the network Clock.connect("192.168.1.100") ``` -------------------------------- ### Accumulate Pattern Values Source: https://foxdot.org/docs/pattern-methods Returns a pattern representing the cumulative sums of the original pattern's values, starting with 0. The 'n' argument specifies the length of the new pattern; if None, it matches the original length. ```python # Accumulation of a series of values >>> print(P[1, 2, 3, 4].accum()) P[0, 1, 3, 6] # The new value can be longer than the original >>> print(P[1, 2, 3, 4].accum(8)) P[0, 1, 3, 6, 10, 11, 13, 16] ``` -------------------------------- ### Python: PRand Generator Usage and Slicing Source: https://foxdot.org/docs/pattern-generators Demonstrates the creation and inspection of a PRand (Pattern Random) generator. It shows how to initialize a PRand with a range, print its representation, and access its values using indexing and slicing to obtain individual numbers or a Pattern of numbers. It also illustrates that a new PRand generates different values unless a seed is specified. ```python >>> my_gen = PRand(0, 10) >>> print(my_gen) PRand(0, 10) >>> my_gen[0] 4 >>> my_gen[1] 6 >>> my_gen[:10] P[4, 6, 1, 8, 3, 8, 8, 8, 0, 1] >>> print(PRand(0, 10)[:10]) P[8, 5, 6, 0, 2, 2, 7, 3, 4, 4] >>> print(PRand(0, 10)[:10]) P[1, 0, 0, 8, 0, 3, 4, 4, 2, 9] >>> print(PRand(0, 10, seed=1)[:10]) P[2, 9, 1, 4, 1, 7, 7, 7, 10, 6] >>> print(PRand(0, 10, seed=1)[:10]) P[2, 9, 1, 4, 1, 7, 7, 7, 10, 6] ``` -------------------------------- ### FoxDot Loop Example (Incorrect Timing) Source: https://foxdot.org/docs/temporal-recursion This FoxDot code snippet demonstrates an incorrect attempt at a timed loop. It runs all code immediately without considering time, leading to the `d1.stop()` call executing instantly. ```python for n in range(21): if 0 > n > 4: d1 >> play("x ") elif 4 > n > 20: d1 >> play("x-") else: d1.stop() ``` -------------------------------- ### FoxDot PGroup Creation with Tuples Source: https://foxdot.org/docs/pattern-basics Illustrates how tuples used within a FoxDot Pattern are converted into PGroups. PGroups keep values together, preventing lacing and allowing simultaneous playback, which is useful for playing chords. ```python >>> pat = P[0, 2, (3, 5)] >>> print(pat) P[0, 2, P(3, 5)] >>> print(pat[0]) 0 >>> print(pat[1]) 2 >>> print(pat[2]) P(3, 5) ``` -------------------------------- ### Basic FoxDot loop synth usage Source: https://foxdot.org/docs/playing-samples Introduces the 'loop' synth for playing longer audio files. It requires the filename and duration in beats. Files in the `FoxDot/snd/_loop_/` directory can be referenced without a full path or extension. ```python p1 >> loop("path/to/my/my_file.wav", dur=32) p1 >> loop("my_file", dur=4) ``` -------------------------------- ### Play Audio File Segments with Loop Synth Source: https://foxdot.org/docs/playing-samples This snippet demonstrates playing specific segments of an audio file using the FoxDot loop synth. It shows how to select beats, control duration, and optionally adjust playback to match the project's tempo by providing the audio file's original tempo. ```python p1 >> loop("my_file", P[:4].shuffle(), dur=1) p1 >> loop("my_file", P[:4], dur=1, tempo=135) p1 >> loop("my_file", P[:8]/2, dur=1/2, tempo=135) ``` -------------------------------- ### FoxDot play synth with successive samples Source: https://foxdot.org/docs/playing-samples Shows how to use square brackets within the 'play' synth sequence to play multiple samples successively within the time of a single step. This is useful for creating triplets or other complex rhythmic figures. ```python p1 >> play("x-o[---]", dur=1) p1 >> play("(x-)(-[-x])o-") p1 >> play("x-o[-(xo)]") ``` -------------------------------- ### Detect MIDI Devices with FoxDot Source: https://foxdot.org/docs/setting-up-midi This code snippet uses FoxDot to detect and list available MIDI devices connected to your system. It's essential for verifying that SuperCollider can recognize your MIDI hardware before sending messages. ```python FoxDot.midi ``` -------------------------------- ### Repeat Pattern Multiple Times - FoxDot Source: https://foxdot.org/docs/pattern-methods The .loop(n) method repeats the pattern n times. It handles nested patterns and can apply a function to values in subsequent loops. Example shows repeating a pattern and chaining it with another. ```Python # Repeat the pattern two times >>> print(P[0, 1, 2, 3].loop(2)) P[0, 1, 2, 3, 0, 1, 2, 3] # Repeat twice and chain with another pattern >>> print(P[0, 1, 2].loop(2) | P[7, 6]) P[0, 1, 2, 0, 1, 2, 7, 6] # Looping with nested patterns expands the nests >>> print(P[0, [1, 2]].loop(2)) P[0, 1, 0, 2, 0, 1, 0, 2] # Repeat the pattern three times and add 7 to the loops >>> print(P[0, 1, 2].loop(3, lambda x: x + 7)) P[0, 1, 2, 7, 8, 9, 14, 15, 16] ``` -------------------------------- ### FoxDot loop synth with position control Source: https://foxdot.org/docs/playing-samples Demonstrates how to control the playback order of a looped audio file using the 'position' argument. This allows iteration through specific parts of the audio file based on duration. ```python p1 >> loop("my_file", P[:4], dur=1) ``` -------------------------------- ### Specify MIDI Channel with MidiOut Source: https://foxdot.org/docs/setting-up-midi This snippet demonstrates how to specify a MIDI channel when using the MidiOut synth in FoxDot. By default, messages are sent on channel 0, but you can select other channels (e.g., channel 1) as needed. ```python p1 >> MidiOut([0,1,2,3], channel = 1) ``` -------------------------------- ### FoxDot PSq: Generate Square Number Patterns Source: https://foxdot.org/docs/pattern-functions PSq creates a Pattern of square numbers within a specified range. It takes arguments 'a' (start), 'b' (unused), and 'c' (number of elements). The pattern includes squares from a*a up to (a+c-1)*(a+c-1). ```python >>> PSq(1, 2, 3) P[1, 4, 9] >>> PSq(2, 2, 5) P[4, 9, 16, 25, 36] ``` -------------------------------- ### FoxDot PBeat: Create Patterns from Textual Rhythms Source: https://foxdot.org/docs/pattern-functions PBeat generates a Pattern of durations based on an input string. Non-whitespace characters represent a pulse, and their sequence determines the rhythm. Optional 'start' and 'dur' parameters allow for rhythm manipulation. ```python >>> PBeat("x xxx x") P[1, 0.5, 0.5, 1, 0.5] >>> PBeat("x xxx x", start=1, dur=1/4) P[0.25, 0.25, 0.5, 0.25, 0.5] ``` -------------------------------- ### Sinusoidal Value Change with sinvar in FoxDot Source: https://foxdot.org/docs/different-types-of-timevar Illustrates the sinvar TimeVar in FoxDot, which changes values based on a sinusoidal wave over a given duration. The example shows how the value changes at a different rate compared to linvar but reaches the same final value. ```python >>> my_sinvar = sinvar([0, 1], 4) >>> print(Clock.now(), my_linvar, my_sinvar) 1, 0.25, 0.38 >>> print(Clock.now(), my_linvar, my_sinvar) 2, 0.50, 0.71 >>> print(Clock.now(), my_linvar, my_sinvar) 3, 0.75, 0.92 >>> print(Clock.now(), my_linvar, my_sinvar) 4, 1, 1 ``` -------------------------------- ### Beat Stretch Audio File with Stretch Synth Source: https://foxdot.org/docs/playing-samples This snippet introduces the `stretch` synth in FoxDot, designed for beat-stretching entire audio files without losing pitch information. It allows playback over a specified duration, automatically adapting to the project's tempo regardless of the audio file's original speed. ```python p1 >> stretch("my_file", dur=4) ``` -------------------------------- ### Use SynthDef with FoxDot Player Source: https://foxdot.org/docs/using-your-own-synthdefs Demonstrates how to use a custom SynthDef (referenced as 'sine' in FoxDot) with a FoxDot player object to play a sequence of notes with specified durations. ```python p1 >> sine([0, 4, 6, 7], dur=1/2) ``` -------------------------------- ### Accompany Player Pitches Source: https://foxdot.org/docs/player-keys Illustrates the use of the .accompany() method to shift player pitches to the nearest value within a specified relative interval. This is useful for creating harmonically related melodies. ```python p1 >> pads([0, 4, 5, 3], dur=4) p2 >> pluck(p1.pitch.accompany()) ``` -------------------------------- ### Utilize Default and Master Groups for Global Control (FoxDot) Source: https://foxdot.org/docs/groups Explains the use of predefined '_all' groups (e.g., d_all) and the Master() group for applying effects or actions to sets of players based on naming conventions or all currently active players. This simplifies managing complex soundscapes. ```foxdot # Assuming d1 and d2 are defined Player objects d1 >> play("x-o-") d2 >> play(" * * *") # Assuming p1 and p2 are defined Player objects p1 >> pads([0, 4, -2, 3], dur=4) p2 >> pluck([0, 1, 3, 4], dur=1/4) # Apply a filter to all players starting with 'p' p_all.hpf = 500 # Stop only the Players beginning with 'd' d_all.stop() # Apply a filter to all currently active Players Master().hpf = 500 # Stop all currently active Players Master().stop() ``` -------------------------------- ### Pitch Bend Effect in FoxDot Source: https://foxdot.org/docs/player-effects The `bend` effect, similar to `slide`, changes a note's frequency over time but crucially returns to the original frequency by the end of the note. `benddelay` can be used to offset the start of the bend. This is ideal for vibrato-like effects or subtle pitch modulations. ```python # Bends one octave up and back again p1 >> pluck(dur=4, bend=1) # Bend to 0 and back again p1 >> pluck(dur=4, bend=-1) # Delay the bend effect to start half way through the note p1 >> pluck(dur=4, slide=0.5, bend=0.5) ``` -------------------------------- ### Slide and Slide From Effects in FoxDot Source: https://foxdot.org/docs/player-effects The `slidefrom` effect modifies a note's frequency, sliding it from a specified starting point to the note's original frequency. The `slidedelay` keyword controls when the slide begins. These effects are useful for creating pitch sweeps and glissando-like sounds. ```python # Slide from one octave up p1 >> pluck(dur=4, slidefrom=1) # Slide from 0 p1 >> pluck(dur=4, slidefrom=-1) # Delay the slide effect to start half way through the note p1 >> pluck(dur=4, slidefrom=0.5, slidedelay=0.5) ``` -------------------------------- ### Playing Chord Sequences with Stuttered Pitches in FoxDot Source: https://foxdot.org/docs/time-dependant-variables An example of how to play a chord sequence using the `pluck` instrument in FoxDot. It utilizes the `stutter` method to control how many times each pitch value is repeated before moving to the next, based on a calculated stutter count. ```python p1 >> pluck(P[0, 3, 0, 4].stutter(32), dur=1/4) + (0, 2, 4) ``` -------------------------------- ### Beat Stretch Audio File with Loop Synth Source: https://foxdot.org/docs/playing-samples This snippet shows how to play an entire audio file at the current project tempo using the `beat_stretch` argument in the loop synth. This method adjusts the audio to fit the specified duration without needing to know the original tempo, but may alter pitch. ```python p1 >> loop("my_file", dur=4, beat_stretch=True) ``` -------------------------------- ### Creating Time-Dependent Variables (TimeVar) in FoxDot Source: https://foxdot.org/docs/time-dependant-variables Illustrates the creation and behavior of TimeVars in FoxDot using the `var` object. TimeVars change their value at specified beat intervals, allowing for dynamic musical changes without manual recalculations. The example shows how the value changes over beats. ```python # Duration can be single value >>> a = var([0,3],4) # 'a' initially has a value of 0 when 0 beats have elapsed >>> print(int(Clock.now()), a) 0, 0 # After 4 beats, the value changes to 3 >>> print(int(Clock.now()), a) 4, 3 # After another 4 beats, the value changes back to 0 >>> print(int(Clock.now()), a) 8, 0 ``` -------------------------------- ### FoxDot Pattern Addition with PGroups Source: https://foxdot.org/docs/pattern-basics Demonstrates how adding tuples or lists of tuples to an existing FoxDot Pattern creates new patterns where elements are combined into PGroups, affecting simultaneous playback. ```python >>> pat = P[0, 3, 5, 4] >>> print(pat + (0, 2)) P[P(0, 2), P(3, 5), P(5, 7), P(4, 6)] >>> print(pat + [(0, 2), (2, 4)]) P[P(0, 2), P(5, 7), P(5, 7), P(6, 8)] ``` -------------------------------- ### FoxDot play synth with random sample selection Source: https://foxdot.org/docs/playing-samples Explains the use of curly braces in the 'play' synth sequence for randomly selecting samples. This adds variation to the playback. ```python p1 >> play("x-o{-ox}") p1 >> play("x-o{[--]ox}") p1 >> play("x-o[-{ox}]") ``` -------------------------------- ### Create Basic SynthDef in SuperCollider Source: https://foxdot.org/docs/using-your-own-synthdefs Defines a basic SynthDef named 'sine' using a sine wave oscillator and a percussion envelope. It includes amplitude, sustain, panning, and frequency as parameters. The output is sent to the default audio bus. ```SuperCollider SynthDef.new(\"sine,\" {|amp=1, sus=1, pan=0, freq=0|\n var osc, env;\n osc=SinOsc.ar(freq, mul: amp);\n env=EnvGen.ar(\n Env.perc(attackTime: 0.01, releaseTime: sus),\n doneAction: 2\n );\n osc=(osc * env);\n osc = Pan2.ar(osc, pan);\n Out.ar(0, osc)}\").add; ``` -------------------------------- ### FoxDot PDur: Create Duration Patterns from Euclidean Rhythms Source: https://foxdot.org/docs/pattern-functions The PDur function generates a Pattern of durations based on the Euclidean algorithm. It takes the number of pulses (n) and the total number of steps (k) as primary arguments, with optional start index and duration values. It's useful for creating rhythmic sequences with varied note lengths. ```python # Basic pattern function >>> PDur(3, 8) P[0.75, 0.75, 0.5] # Use a list/Pattern to join together two patterns using the same function >>> PDur([3, 2], [8, 4]) P[0.75, 0.75, 0.5, 0.5, 0.5] # Use a TimeVar to create a Pvar >>> PDur(var([3, 5]), 8) P[0.75, 0.75, 0.5] # Equal to PDur(3,8) P[0.5, 0.25, 0.5, 0.25, 0.5] # Equal to PDur(5,8) after 4 beats >>> PDur(3, 8) P[0.75, 0.75, 0.5] >>> PDur(3, 8, 1) P[0.75, 0.5, 0.75] >>> PDur(3, 8, 1, 0.5) P[1.5, 1.0, 1.5] ```