Class Bagatelle

java.lang.Object
processing.core.PApplet
net.paulhertz.pixelaudio.example.Bagatelle
All Implemented Interfaces:
PANetworkClientINF, processing.core.PConstants

public class Bagatelle extends processing.core.PApplet implements PANetworkClientINF
Experimental real time performance application, with an editing GUI, presets, and JSON-format files for persistent brushstroke and audio configuration data. Used in performance at the Outside the Box New Music Festival at Southern Illinois University, Carbondale, March 2026. We played Christopher Walczak's composition "Abstract Jailbreak", one of a series of "Bagatelles" we are collaborating on, and my composition "DEADBODYWORKFLOW".

The presets and performance cues in this version of the Bagatelle sketch are set up for "Abstract Jailbreak". If you change pMode to PerformanceMode.DEADBODYWORKFLOW, this sketch will run the presets and cues for "DEADBODYWORKFLOW". You can toggle pMode at runtime with the '%' key--this is new feature, YMMV.

Bagatelle is an experiment. I have tried to document it reasonably well, but some features are bound to appear opaque or mysterious. I think most of the features will reveal themselves with experimentation. You may even find that you can write your own presets and use them for your performances. That would be an ideal outcome, to my mind.

QUICK START

  1. Launch the sketch. A display window and a palette of Graphical User Interface (GUI) controls appears. The display window has an audio file preloaded. The grayscale values in the image are transcoded audio samples. An overlaid rainbow spectrum traces the Signal Path, the mapping of the audio signal to the image pixels created by the PixelMapGen multigen and managed by the PixelAudioMapper mapper. The Signal Path starts in the upper left corner and ends in the lower right corner.

    Bagatelle is set up for a performance of "Abstract Jailbreak," a musical work by Christopher Walczak. Abstract Jailbreak makes use of the Performance Presets built in to the application. The presets can be triggered with the number keys. At this point you could press '1' to load the first preset. For more information, see the "PRESET LIST" in the variables section of the Bagatelle tab, and the various methods in the Performance tab. There are five presets for Abstract Jailbreak. They control audio synthesis parameters and brush drawing style. More than one can be loaded at one time. To clear presets from the preset stack, press '0'.

  2. Drawing is already turned on, so go ahead and drag the mouse to draw a line. As in TutorialOne_03_Drawing, a brushstroke appears when you release the mouse. TutorialOne_03_Drawing gave you limited control over the attributes of a brushstroke and its associated audio parameters. In GesturePlayground, you can control nearly all the available parameters with the control palette. Building on GesturePlayground, Bagatelle provides a framework for live performance.

  3. You can probably use Bagatelle "right out of the box" by just supplying your own audio and image files and open your files with the 'o' key command. If you want to use your own files with Bagatelle's PerformancePreset feature, I suggest you look closely at the existing presets (for Abstract Jailbreak) and at the runPerformanceCue(...) method in the Performance Methods section of this app. There are three things you need to modify to use your own performance presets:
    1. Create your own PerformancePreset list by editing the existing one.
    2. Set the variable performanceBasePath to point to the directory where you store your performance files
    3. Edit the entries in runPerformanceCue(...) to access your own files

  4. At the top of the control palette, you'll find Path Source radio buttons and sliders for setting the geometry of the brush curve. When the curve is set to Reduced Points or Curve Points, the epsilon slider will allow you to visualize changes in the curve. For the curve points representation of the curve, theCurve Points slider will add or subtract points.

  5. The control palette displays knobs for the type of audio synthesis instrument you have selected. Press the 't' key to change the instrument. The control palette will reflect the changes. The control palette provides three play modes: one for editing granular synthesis parameters, another for the sampler synthesizer, and a "play only" mode where you can play both instruments but don't have editing enabled.

  6. The controls for the Sampler are fairly simple. You can change the number of points in the curve with the geometry controls. You can also change the duration of the gesture and the number of points in it with the Resample and Duration sliders. Finally, there's a Sampler Envelope menu that will change the ADSR envelope of each sampler event point.

  7. The Granular Synth has all the controls of the Sampler synth except for the envelopes, plus many controls for granular synthesis:
    1. The Hop Mode radio buttons determine if the duration of the granular event is determined by the gesture timing data in the brushstroke's PACurveMaker instance, or by the Grain Length and Hop Length sliders.
    2. Burst Count sets the number of linear grains at each event point. Its effect is to expand the sound of the grain.
    3. Grain Length and Hop Length sliders control the spacing of the grains. Hop Length is only used for Fixed Hop Mode. Grain and Hop durations are in milliseconds.
    4. The Warp radio buttons and slider control non-linear timing changes to the gesture.


  8. There are many key commands too, including the 'o' command to load a new audio files. Some commands are particularly useful with granular synthesis:
    1. The 'q' command key will calculate the optimal number of grains in a gesture (usually in GESTURE Path Mode) and update the control palette. This can provide smooth granular synthesis even as it preserves the timing characteristic of the gesture.
    2. The 'u' command will apply grain optimization to every new granular brush.
    3. the 'd' command will toggle playing a new brush immediately upon mouse release.
    4. The 'D' command will toggle playing audio while you draw.
    5. The 'c' command key will print configuration data to the console.
    6. The 'x' command key deletes the brush you are hovering over, if it is editable.
    7. The 'z' command key swaps the instrument type of the brush you are hovering over and changes edit mode to match.


About Bagatelle

Bagatelle uses a GUI to view and manage the properties of the AudioBrush subclasses GranularBrush and SamplerBrush, the GestureSchedule class, and the Sampler and Granular audio synthesis instruments PASamplerInstrumentPool and PAGranularInstrumentDirector.

An AudioBrush combines a PACurveMaker and a GestureGranularConfig.Builder. PACurveMaker models gestures, one of the core concepts of PixelAudio. In its simplest encoded form, the PAGesture interface, a gesture consists of an array of points and an array of times. The times array and the points array must be the same size, because the times array records the times when something as-yet-unspecified will happen at the corresponding point in the points array. In my demos for PixelAudio, what happens at a point is typically an audio event and an animation event. The sound happens at the point because points in PixelAudio map onto locations in the sound buffer. Mapping of bitmap locations onto audio buffer indices is another core concept of PixelAudio. Gestures over the 2D space of an image become paths through audio buffers.

The audio buffer is traversed either by a granular synthesis engine or by a sampling synthesizer. For the granular synth, a gesture corresponds to a non-linear traversal of an audio buffer, potentially as a continuous sequence of overlapping grains with a single envelope. The sampling synthesizer treats each point as a discrete event with its own envelope. Depending on how gestures and schedules are structured, the two synthesizers can sound very similar, but there are possibilities in each that the other cannot realize. As you might expect, GranularBrush implements granular synth events and SamplerBrush implements sampler synth events. Both rely on PACUrveMaker which, in addition to capturing the raw gesture of drawing a line, provides methods to reduce points / times and create Bezier paths. PACurveMaker data can also be modified by changing duration, interpolating samples, or non-linear time warping. DeadBodyWorkFlow uses GestureScheduleBuilder to interpolate and warp time and point lists.

The parameters for gesture modeling, granular and sampling synthesis, time and sample interpolation, and audio events are modeled in the GUI, which uses GestureGranularConfig.Builder gConfig to track its current state. A GestureGranularConfig instance is associated with each AudioBrush. When you click on an AudioBrush and activate it, its configuration data is loaded to the GUI and you can edit it. It will be saved to the brush when you select another brush or change the edit mode. When a brush is activated with a click, the schedule is built from its PACurveMaker and GestureGranularConfig.Builder instance variables:

GestureSchedule schedule = scheduleBuilder.build(gb.curve(), cfg.build(), audioOut.sampleRate());

The calling chain for a GranularBrush:
mouseClicked() calls scheduleGranularBrushClick(gb, x, y);.
In scheduleGranularBrushClick(...) we get a reference to the audio buffer buf and then use the PACurveMaker object gb.curve() and gb.snapshot() to build a GestureSchedule, sched.
sched gets timing and location information for the gesture from gb.curve() and modifies it with the settings from the control palette which are stored gb.snapshot().
We port the granular synthesis parameters from the brush to a GestureGranularParams object, and then call playGranularGesture(buf, sched, gParams) to play the granular synth. We also call storeGranularCurveTL(...), which sets up UI animation events to track the grains.
Parameter buf is the audio signal that is the source of our grains, parameter sched provides the points and times for grains and parameter params provides the core parameters for granular synthesis.
playGranularGesture() builds arrays for buffer position and pan for each individual grain and then calls gDir.playGestureNow(buf, sched, params, startIndices, panPerGrain) to play the PAGranularInstrumentDirector granular synth. The 'p' command key can toggle per-grain pitch jitter, which calls playGestureNow()in a slightly different way. See playGranularGesture() for details.
PAGranularInstrumentDirector its own calling chain that goes all the way down to the individual sample level using the Minim library's UGen interface. If you just want to play music, you'll probably never have to deal with the hierarchy of classes directly, but comments PAGranularInstrumentDirector may be useful.

Part of the calling chain for a SamplerBrush:
mouseClicked() calls scheduleSamplerBrushClick(sb, x, y).
In scheduleSamplerBrushClick() we get array of points on the curve with getPathPoints(sb) and then use sb.snapshot() and scheduleBuilder.build() to build a GestureSchedule
Finally, we pass the schedule, snapshot and start time to storeSamplerBrushEvents(), an array of SamplerBrushEvent objects that is checked at every pass through the draw() loop and posts both Sampler instrument triggers and animation events. Unlike the Granular instrument, which requires very accurate timing, the Sampler synth requires less precision, so we can handle it through the UI frames. Sample-accurate timing is a topic for another as-yet-unreleased example sketch.
The runSamplerBrushEvents() method executes the UI brushstroke animation and the Sampler audio events. Sampler events all pass through pool.playSample(samplePos, samplelen, amplitude, env, pitch, pan).

 ----- Audio Gain -----
 Press UP ARROW to increase audio output volume by 1.0 or 3.0 dB (+shift).
 Press DOWN ARROW to decrease audio output volume by 1.0 or 3.0 dB (+shift).
 Press RIGHT ARROW to increase current instrument gain by 3.0 dB.
 Press LEFT ARROW to decrease current instrument gain by 3.0 dB.
 Press '`' to fade out all instruments.
 ----- Presets and Cues -----
 Keys 1 through 9 are reserved for triggering Performance Presets 1-9, '0' will clear all presets.
 ----- Drawing, Audio Settings, Playback -----
 Press TAB to set brush to active, if cursor is over a brush.
 Press ' ' to (spacebar) trigger a brush if we're hovering over a brush, otherwise trigger a point event.
 Press 'm' to toggle doMagicClick, play brushstroke in same rectangle as mouse on click or spacebar.
 Press 'a' to toggle animation.
 Press 't' to switch between Granular, Sampler, and Play Only modes.
 Press 'z' to change the drawing mode of the hover brush.
 Press 'q' to automatically set an active GRANULAR brush to have an optimized number of samples.
 Press 'u' to toggle granular sample optimization: same as the 'q' command, applied on brushstroke creation.
 Press 'd' to toggle doPlayOnNewBrush: if true, audio plays when a new brush is created.
 Press 'D' to toggle doPlayOnDraw: if true, drawing triggers audio while you drag the mouse.
 Press 'p' to jitter the pitch of granular gestures.
 Press 'k' to apply the hue and saturation in the colors array to mapImage (not to baseImage).
 Press 'K' to apply hue and saturation in colors to baseImage and mapImage.
 Press 'r' to reset instrument configuration to defaults in GUI.
 Press 'c' or 'C' to print the current configuration status to the console.
 ----- File IO and Mapping -----
 Press 'f' or 'F' to open a folder with JSON brush data and load all files.
 Press 'j' to save the active brush curve and config to JSON files.
 Press 'J' to save all brushes curve and config to JSON Session file.
 Press 'o' to open an audio file, image file, or JSON file.
 Press 'b' or 'B' to toggle loading data to both image and audio buffers when you open a file.
 Press 'w' to write the display image to the audio buffer.
 Press 'W' to write the audio buffer to the display image.
 ----- Audio Mix Dynamics -----
 Press 'n' to set noise reduction policy for Sampler instrument audio mix.
 Press 'E' to toggle whether we adjust envelope duration in relation to gesture duration.
 Press 'g' to toggle use of dynamics in gainCurve with gesture .
 ----- Special FX -----
 Press 'l' to loop the hovered brush 4 times.
 Press 'L' to run an infinite loop on the hovered brush.
 Press ';' to stop loop for the hovered brush.
 Press ':' to stop all loops.
 Press 'y' to toggle transform animation test.
 Press 'Y' to freeze / unfreeze brush geometric transform animation.
 Press 'R' to reset transform of active brush if it has a transform.
 Press 'G' to create a beatBrush.
 Press '.' to turn random raindrops audio events on or off.
 Press '`' to fade out all instruments.
 Press '%' to switch performance presets and cue handlers.
 Press '&' to clear events in granular and sample synths.
 ----- Brush Deletion -----
 Press 'x' to delete the current active brush shape or the oldest brush shape.
 Press 'X' to delete the most recent brush shape.
 Press '≈' to option-x on MacOS keyboard, clear all brushes.
 ----- Network -----
 Press ']' to send UDP message to Max (simpleAudioIO.maxpat): reverb ON.
 Press '[' to send UDP message to Max (simpleAudioIO.maxpat): reverb OFF.
 Press '}' to send UDP message to Max (simpleAudioIO.maxpat): unused.
 Press '{' to send UDP message to Max (simpleAudioIO.maxpat): unused.
 Press 'v' to send UDP message to Max (simpleAudioIO.maxpat): small reverb settings.
 Press 'V' to send UDP message to Max (simpleAudioIO.maxpat): big reverb settings.
 ----- Help -----
 Press 'h' or 'H' to show help message.
 

MacOS AUDIO TO MAX SETUP

In MacOS:
Ignore Sound.inputDevice() and Sound.outputDevice(), use the System Settings instead.
Set Output to BlackHole 16ch
Set Input to your external audio hardware, for an external mic: mine is Volt2

Then in Max Audio Status control panel:
Set Input Device to BlackHole 16ch
Set Output Device to your external audio hardware, e.g. Volt2
Create a patcher that gets signals from an adc~, route the adc~ to some sort of effects and out to a dac~.
  • Field Details

    • pixelaudio

      PixelAudio pixelaudio
    • multigen

      MultiGen multigen
    • genWidth

      int genWidth
    • genHeight

      int genHeight
    • mapper

    • mapSize

      int mapSize
    • baseImage

      processing.core.PImage baseImage
    • mapImage

      processing.core.PImage mapImage
    • chan

    • colors

      int[] colors
    • audioFile

      File audioFile
    • audioFilePath

      String audioFilePath
    • audioFileName

      String audioFileName
    • audioFileTag

      String audioFileTag
    • audioFileLength

      int audioFileLength
    • imageFile

      File imageFile
    • imageFilePath

      String imageFilePath
    • imageFileName

      String imageFileName
    • imageFileTag

      String imageFileTag
    • imageFileWidth

      int imageFileWidth
    • imageFileHeight

      int imageFileHeight
    • isLoadToBoth

      boolean isLoadToBoth
    • isBlending

      boolean isBlending
    • minim

      ddf.minim.Minim minim
      Minim audio library
    • audioOut

      ddf.minim.AudioOutput audioOut
    • sampleRate

      float sampleRate
    • fileSampleRate

      float fileSampleRate
    • bufferSampleRate

      float bufferSampleRate
    • doResample

      boolean doResample
    • audioSignal

      float[] audioSignal
    • playBuffer

      ddf.minim.MultiChannelBuffer playBuffer
    • samplePos

      int samplePos
    • audioLength

      int audioLength
    • samplerEnv

      ADSRParams samplerEnv
    • granularEnv

      ADSRParams granularEnv
    • noteDuration

      final int noteDuration
      See Also:
    • envDuration

      int envDuration
    • isAdjustEnvelope

      boolean isAdjustEnvelope
    • overlapFactor

      float overlapFactor
    • envMinDurationMs

      int envMinDurationMs
    • envMaxDurationMs

      int envMaxDurationMs
    • samplelen

      int samplelen
    • samplerGain

      float samplerGain
    • samplerPointGain

      float samplerPointGain
    • outputGain

      float outputGain
    • isMuted

      boolean isMuted
    • pool

    • poolSize

      int poolSize
    • sMaxVoices

      int sMaxVoices
    • granSignal

      public float[] granSignal
    • gSynth

      public PAGranularInstrument gSynth
    • curveSteps

      public int curveSteps
    • granLength

      public int granLength
    • granHop

      public int granHop
    • gMaxVoices

      public int gMaxVoices
    • currentGranStatus

      String currentGranStatus
    • gDir

    • granularGain

      public float granularGain
    • granularPointGain

      public float granularPointGain
    • useShortGrain

      boolean useShortGrain
    • longSample

      int longSample
    • shortSample

      int shortSample
    • granSamples

      int granSamples
    • hopSamples

      int hopSamples
    • gParamsFixed

      GestureGranularParams gParamsFixed
    • gParamsDraw

    • useLongBursts

      boolean useLongBursts
    • maxBurstGrains

      int maxBurstGrains
    • burstGrains

      int burstGrains
    • shift

      int shift
    • leap

      int leap
    • totalShift

      int totalShift
    • isAnimating

      boolean isAnimating
    • oldIsAnimating

      boolean oldIsAnimating
    • isTrackMouse

      boolean isTrackMouse
    • animSteps

      int animSteps
    • isRecordingVideo

      boolean isRecordingVideo
    • videoFrameRate

      int videoFrameRate
    • videoSteps

      int videoSteps
    • step

      int step
    • videx

      com.hamoid.VideoExport videx
    • curveMaker

      public PACurveMaker curveMaker
    • isDrawMode

      public boolean isDrawMode
    • epsilon

      public float epsilon
    • currentPoint

      public processing.core.PVector currentPoint
    • allPoints

      public ArrayList<processing.core.PVector> allPoints
    • allTimes

      public ArrayList<Integer> allTimes
    • startTime

      public int startTime
    • dragColor

      public int dragColor
    • dragWeight

      public float dragWeight
    • polySteps

      public int polySteps
    • readyGranColor

      int readyGranColor
    • hoverGranColor

      int hoverGranColor
    • activeGranColor

      int activeGranColor
    • readySamplerColor

      int readySamplerColor
    • hoverSamplerColor

      int hoverSamplerColor
    • activeSamplerColor

      int activeSamplerColor
    • dimmedBrushColor

      int dimmedBrushColor
    • circleColor

      int circleColor
    • dimCircleColor

      int dimCircleColor
    • lineColor

      int lineColor
    • dimLineColor

      int dimLineColor
    • animatedCircleColor

      int animatedCircleColor
    • isIgnoreOutsideBounds

      boolean isIgnoreOutsideBounds
    • hoverBrush

      private AudioBrush hoverBrush
      AudioBrush wraps a PACurveMaker (gesture) and a GestureGranularConfig.Builder (granular synthesis parameters)
    • hoverIndex

      private int hoverIndex
    • activeBrush

      private AudioBrush activeBrush
    • granularBrushes

      ArrayList<GranularBrush> granularBrushes
    • activeGranularBrush

      GranularBrush activeGranularBrush
    • activeGranularIndex

      int activeGranularIndex
    • samplerBrushes

      ArrayList<SamplerBrush> samplerBrushes
    • activeSamplerBrush

      SamplerBrush activeSamplerBrush
    • activeSamplerIndex

      int activeSamplerIndex
    • pointTimeLocs

      ArrayList<TimedLocation> pointTimeLocs
    • samplerBrushEvents

      ArrayList<SamplerBrushEvent> samplerBrushEvents
    • grainTimeLocs

      ArrayList<TimedLocation> grainTimeLocs
    • pointTimeLocsLock

      final Object pointTimeLocsLock
    • samplerBrushEventsLock

      final Object samplerBrushEventsLock
    • grainTimeLocsLock

      final Object grainTimeLocsLock
    • pointEventUseSampler

      boolean pointEventUseSampler
    • runningFadeOut

      boolean runningFadeOut
    • gConfig

    • defaultGranConfig

      final GestureGranularConfig.Builder defaultGranConfig
    • defaultSampConfig

      final GestureGranularConfig.Builder defaultSampConfig
    • guiSyncing

      boolean guiSyncing
    • baselineCount

      int baselineCount
    • baselineDurationMs

      int baselineDurationMs
    • scheduleBuilder

      GestureScheduleBuilder scheduleBuilder
    • drawingMode

    • CURVE_STEPS_HARD_MAX

      static final int CURVE_STEPS_HARD_MAX
      See Also:
    • CURVE_STEPS_SAFE_MAX

      static final int CURVE_STEPS_SAFE_MAX
      See Also:
    • CURVE_STEPS_FLOOR

      static final int CURVE_STEPS_FLOOR
      See Also:
    • audioSched

    • hopScale

      float hopScale
    • optGrainCount

      int optGrainCount
    • eventStep

      int eventStep
    • isSaveConfig

      boolean isSaveConfig
    • drawTasteIntervalMs

      int drawTasteIntervalMs
    • drawTasteMinDist

      float drawTasteMinDist
    • drawTasteDurationMs

      int drawTasteDurationMs
    • drawTasteMaxGrains

      int drawTasteMaxGrains
    • drawTasteBurstGrains

      int drawTasteBurstGrains
    • lastDrawTasteMs

      int lastDrawTasteMs
    • lastDrawTastePoint

      processing.core.PVector lastDrawTastePoint
    • activeLoops

      final ArrayList<Bagatelle.InstrumentLoop> activeLoops
    • aj_presetStack

    • dbwf_presetStack

    • isVerbose

      boolean isVerbose
    • isDebugging

      boolean isDebugging
    • isTrackSamplerVoices

      boolean isTrackSamplerVoices
    • shiftIsDown

      boolean shiftIsDown
    • pMode

      current performance mode
    • doPlayOnNewBrush

      boolean doPlayOnNewBrush
    • doPlayWhileDrawing

      boolean doPlayWhileDrawing
    • isAutoOptimize

      boolean isAutoOptimize
    • doMagicClick

      boolean doMagicClick
    • usePitchedGrains

      boolean usePitchedGrains
    • pitchJitter

      float pitchJitter
    • applyColorMapOnLoad

      boolean applyColorMapOnLoad
    • isReplaceBrushes

      boolean isReplaceBrushes
    • isSaveSession

      boolean isSaveSession
    • isRaining

      boolean isRaining
    • isAddDynamics

      boolean isAddDynamics
    • dynamics

      PAControlCurve dynamics
    • isBrushTransformTest

      boolean isBrushTransformTest
    • isBrushTransformFrozen

      boolean isBrushTransformFrozen
    • isBrushSelectionModal

      boolean isBrushSelectionModal
    • boundaryMode

    • boundsPolicy

      PABoundsPolicy boundsPolicy
    • nd

    • isUseNetworkDelegate

      boolean isUseNetworkDelegate
    • isNetSendDrawingPoints

      boolean isNetSendDrawingPoints
    • isNetSendOutsideBrushPoints

      boolean isNetSendOutsideBrushPoints
    • isNetSendBrushTriggers

      boolean isNetSendBrushTriggers
    • isNetSendFileInfo

      boolean isNetSendFileInfo
    • isNetSendGestures

      boolean isNetSendGestures
    • performanceBasePath

      static String performanceBasePath
    • daPath

      String daPath
    • daFilename

      String daFilename
    • daFilelist

      ArrayList<String> daFilelist
    • controlWindow

      g4p_controls.GWindow controlWindow
    • controlPanel

      g4p_controls.GPanel controlPanel
    • pathSourceLabel

      g4p_controls.GLabel pathSourceLabel
    • pathSourceGroup

      g4p_controls.GToggleGroup pathSourceGroup
    • allOption

      g4p_controls.GOption allOption
    • rdpOption

      g4p_controls.GOption rdpOption
    • curveOption

      g4p_controls.GOption curveOption
    • rdpEpsilonSlider

      g4p_controls.GSlider rdpEpsilonSlider
    • curvePointsSlider

      g4p_controls.GSlider curvePointsSlider
    • pitchLabel

      g4p_controls.GLabel pitchLabel
    • pitchShiftText

      g4p_controls.GTextField pitchShiftText
    • resampleLabel

      g4p_controls.GLabel resampleLabel
    • resampleSlider

      g4p_controls.GSlider resampleSlider
    • resampleField

      g4p_controls.GTextField resampleField
    • durationLabel

      g4p_controls.GLabel durationLabel
    • durationSlider

      g4p_controls.GSlider durationSlider
    • durationField

      g4p_controls.GTextField durationField
    • burstLabel

      g4p_controls.GLabel burstLabel
    • burstSlider

      g4p_controls.GSlider burstSlider
    • hopModeLabel

      g4p_controls.GLabel hopModeLabel
    • hopModeGroup

      g4p_controls.GToggleGroup hopModeGroup
    • gestureOption

      g4p_controls.GOption gestureOption
    • grainLengthLabel

      g4p_controls.GLabel grainLengthLabel
    • grainLengthSlider

      g4p_controls.GSlider grainLengthSlider
    • hopLengthLabel

      g4p_controls.GLabel hopLengthLabel
    • hopLengthSlider

      g4p_controls.GSlider hopLengthSlider
    • fixedOption

      g4p_controls.GOption fixedOption
    • warpLabel

      g4p_controls.GLabel warpLabel
    • warpSlider

      g4p_controls.GSlider warpSlider
    • epsilonSliderLabel

      g4p_controls.GLabel epsilonSliderLabel
    • curvePointsLabel

      g4p_controls.GLabel curvePointsLabel
    • gainLabel

      g4p_controls.GLabel gainLabel
    • gainSlider

      g4p_controls.GSlider gainSlider
    • grainLengthField

      g4p_controls.GTextField grainLengthField
    • hopLengthField

      g4p_controls.GTextField hopLengthField
    • warpGroup

      g4p_controls.GToggleGroup warpGroup
    • linearWarpOption

      g4p_controls.GOption linearWarpOption
    • expWarpOption

      g4p_controls.GOption expWarpOption
    • squareRootOption

      g4p_controls.GOption squareRootOption
    • customWarpOption

      g4p_controls.GOption customWarpOption
    • arcLengthTimeOption

      g4p_controls.GOption arcLengthTimeOption
    • envelopeLabel

      g4p_controls.GLabel envelopeLabel
    • envelopeMenu

      g4p_controls.GDropList envelopeMenu
    • ENV_CUSTOM

      static final String ENV_CUSTOM
      See Also:
    • envPresetItems

      String[] envPresetItems
    • presetIndex

      int presetIndex
    • envelopeValuesLabel

      g4p_controls.GLabel envelopeValuesLabel
    • commentsField

      g4p_controls.GTextArea commentsField
  • Constructor Details

    • Bagatelle

      public Bagatelle()
  • Method Details

    • main

      public static void main(String[] args)
      Parameters:
      args -
    • settings

      public void settings()
      Overrides:
      settings in class processing.core.PApplet
    • setup

      public void setup()
      Overrides:
      setup in class processing.core.PApplet
    • stop

      public void stop()
      turn off audio processing when we exit
      Overrides:
      stop in class processing.core.PApplet
    • loadWordGen

      public MultiGen loadWordGen(int wordGenW, int wordGenH)
      Adds PixelMapGen objects to the local variable genList. The genList initializes a MultiGen, which can be used to map audio and pixel data. Generation order in offsetList follows the words in the workFlowPanel.png graphic.
      Parameters:
      wordGenW - width of single gen element
      wordGenH - height of single gen element
      Returns:
      a MultiGen for DEADBODYWORKFLOW performance
    • getColors

      public int[] getColors(int size)
      Generates an array of rainbow colors using the HSB color space.
      Parameters:
      size - the number of entries in the colors array
      Returns:
      an array of RGB colors ordered by hue
    • initImages

      public void initImages()
      Initializes mapImage with the colors array. mapImage handles the color data for mapper and also serves as our display image. baseImage is a reference image that usually only changes when you open a new image file.
    • initDrawing

      public void initDrawing()
      Initializes drawing and drawing interaction variables.
    • initConfig

      public void initConfig()
      Initializes default settings for granular synthesis, defaultGranConfig, and for sampler synthesis, defaultSampConfig.
    • initGUI

      public void initGUI()
      Initializes the control palette.
    • performanceTitle

      String performanceTitle()
      Returns:
      display title for the current performance mode
    • loadPerformanceGen

      MultiGen loadPerformanceGen()
      Returns:
      a MultiGen appropriate to the current performance mode
    • initCustomSettings

      void initCustomSettings()
      Initializes performance presets and cues, including path to performance files, and loads initial audio image files.
    • initNetwork

      void initNetwork()
      Sets up network for UDP communication.
    • preloadFiles

      public void preloadFiles(String path, String fileName)
      Preload an audio file using a file path and a filename.
      Parameters:
      path - the fully qualified path to the file's directory, ending with a '/'
      fileName - the name of the file
    • draw

      public void draw()
      Overrides:
      draw in class processing.core.PApplet
    • animate

      public void animate()
    • stepAnimation

      public void stepAnimation()
      Step through the animation, called by the draw() method. Will also record a frame of video, if we're recording.
    • renderFrame

      public void renderFrame(int step)
      Renders a frame of pixel-shifting animation: moving along the signal path, copies baseImage pixels to mapImage pixels, adjusting the index position of the copy using totalShift -- i.e. we don't actually rotate the pixels, we just shift the position they're copied to.
      Parameters:
      step - current animation step
    • handleDrawing

      public void handleDrawing()
      Handles user's drawing actions, draws previously recorded brushstrokes, tracks and generates animation and audio events.
    • findHoverHit

      Bagatelle.BrushHit findHoverHit()
      Returns:
      a reference to the brushstroke the mouse is over, or null if there's no brushstroke.
    • updateHover

      void updateHover()
      Update the hoverBrush and hoverIndex global variables.
    • getBrushInRect

      Bagatelle.BrushHit getBrushInRect(int x, int y, int wStep, int hStep)
      Tests whether a supplied coordinate pair is within a rectangular tile that contains a brush, if so, returns the brush in a BrushHit object.
      Parameters:
      x - x-coordinate to test
      y - y-coordinate to test
      wStep - tiling rectangle offset on x-axis
      hStep - tiling rectangle offset on y-axis
      Returns:
      a BrushHit object or null, if no brush was selected
    • containsPoint

      public static boolean containsPoint(float x, float y, float[] r)
      Parameters:
      x - x-coordinate of point to test
      y - y-coordinate of point to test
      r - rectangle to test
      Returns:
      true if r contains the specified point
    • writeToScreen

      public void writeToScreen(String msg, int x, int y, int weight, boolean isWhite)
      Displays a line of text to the screen, usually in the draw loop. Handy for debugging. typical call: writeToScreen("When does the mind stop and the world begin?", 64, 1000, 24, true);
      Parameters:
      msg - message to write
      x - x coordinate
      y - y coordinate
      weight - font weight
      isWhite - if true, white text, otherwise, black text
    • mousePressed

      public void mousePressed()
      The built-in mousePressed handler for Processing, used to begin drawing.
      Overrides:
      mousePressed in class processing.core.PApplet
    • mouseDragged

      public void mouseDragged()
      Overrides:
      mouseDragged in class processing.core.PApplet
    • mouseReleased

      public void mouseReleased()
      Overrides:
      mouseReleased in class processing.core.PApplet
    • mouseClicked

      public void mouseClicked()
      Overrides:
      mouseClicked in class processing.core.PApplet
    • keyPressed

      public void keyPressed()
      built-in keyPressed handler, forwards events to parseKey.
      Overrides:
      keyPressed in class processing.core.PApplet
    • keyReleased

      public void keyReleased()
      Overrides:
      keyReleased in class processing.core.PApplet
    • parseKey

      public void parseKey(char key, int keyCode)
      Handles key press events passed on by the built-in keyPressed method. By moving key event handling outside the built-in keyPressed method, we make it possible to post key commands without an actual key event. Methods and interfaces and even other threads can call parseKey(). This opens up many possibilities and a some risks, too.
      Specified by:
      parseKey in interface PANetworkClientINF
      Parameters:
      key - char for key that was pressed
      keyCode - numeric code for key that was pressed
    • showHelp

      public void showHelp()
      to generate help output, run RegEx search/replace on parseKey case lines with: // case ('.'): // (.+) // println(" * Press $1 to $2.");
    • numericKey

      void numericKey(char key)
      Parameters:
      key - key that was pressed (should be a number key)
    • runAJ_PerformancePreset

      public void runAJ_PerformancePreset(Bagatelle.AJ_PerformancePreset cue, char key)
      Handles cue and performance preset commands for "Abstract Jailbreak".
      Parameters:
      cue - a performance preset
      key - char for the key that triggered the call
    • runDBWF_PerformancePreset

      public void runDBWF_PerformancePreset(Bagatelle.DBWF_PerformancePreset cue, char key)
      Handles cue and performance preset commands for "DEADBODYWORKFLOW".
      Parameters:
      cue - a performance preset
      key - char for the key that triggered the call
    • runPerformanceCue

      void runPerformanceCue(char key)
      Runs cues for live performance of "Abstract Jailbreak" or "DEADBODYWORKFLOW".
      Parameters:
      key - a char used to trigger performance cues
    • resetPerformanceState

      void resetPerformanceState()
      Resets variables that may have been altered from expected base states by performance cues and presets.
    • setPerformanceMode

      void setPerformanceMode(Bagatelle.PerformanceMode newMode, boolean recolorAfterLoad)
      Changes the current performance mode during live performance. Currently there are only two performance modes in Bagatelle, ABSTRACT_JAILBREAK and DEADBODYWORKFLOW.
      Parameters:
      newMode - a new performance mode
      recolorAfterLoad - apply signal path spectrum to display image or not
    • clearGranularActivity

      void clearGranularActivity()
    • clearSynthEvents

      void clearSynthEvents()
    • applyColorMapToDisplay

      public void applyColorMapToDisplay(boolean updateBaseImage)
      Apply color map hue and saturation to mapImage or baseImage.
    • openBrushEditor

      public void openBrushEditor(AudioBrush brush)
      Sets GUI to edit a brush.
      Parameters:
      brush - the AudioBrush to accept for editing
    • setAudioGain

      public void setAudioGain(float g)
      Sets audioOut.gain.
      Parameters:
      g - new value for audioOut, in decibels
    • adjustAudioGain

      public void adjustAudioGain(float g)
      Adjusts audioOut.gain.
      Parameters:
      g - value to add to audioOut.gain, in decibels
    • adjustInstrumentGain

      public void adjustInstrumentGain(float g)
      Adjusts current instrument gain in dB.
      Parameters:
      g - gain increment or decrement, in decibels
    • adjustSamplerGain

      public void adjustSamplerGain(float g)
      Adjusts Sampler instrument pool gain in dB.
      Parameters:
      g - gain increment or decrement, in decibels
    • adjustGranGain

      public void adjustGranGain(float g)
      Adjusts Granular instrument gain in dB.
      Parameters:
      g - gain increment or decrement, in decibels
    • setMode

      void setMode(Bagatelle.DrawingMode newMode)
      Sets the drawing mode to one of {DRAW_EDIT_GRANULAR, DRAW_EDIT_SAMPLER, PLAY_ONLY}.
      Parameters:
      newMode -
    • optimizeActiveBrush

      public void optimizeActiveBrush()
      optimize grainCount for the activeBrush, most useful for granular brushes
    • resetConfigForMode

      void resetConfigForMode()
      Reset tool config to defaults (copy, so default config never mutates).
    • fadeOutGranularNow

      public void fadeOutGranularNow()
    • stopGranularNow

      public void stopGranularNow()
    • suspendScheduledEvents

      public void suspendScheduledEvents()
    • generateSamplerBeatBrush

      public SamplerBrush generateSamplerBeatBrush(int count, int intervalMs)
      Generates a SamplerBrush in code.
      Parameters:
      count - number of points to draw
      intervalMs - interval between points (milliseconds)
      Returns:
      a SamplerBrush with requested characteristics
    • generateGranularBeatBrush

      public GranularBrush generateGranularBeatBrush(int count, int intervalMs)
      Generates a GranularBrush in code.
      Parameters:
      count - number of points to draw
      intervalMs - interval between points (milliseconds)
      Returns:
      a GranularBrush with requested characteristics
    • raindrops

      public void raindrops()
      Triggers a sample at a random location.
    • runRaindropPointEvent

      void runRaindropPointEvent(int x, int y)
      Plays a sample and animates a point
      Parameters:
      x - x-coordinate of event
      y - y-coordinate of event
    • chooseFile

      public void chooseFile()
      Wrapper method for Processing's selectInput command
    • fileSelected

      public void fileSelected(File selectedFile)
      callback method for chooseFile(), handles standard audio and image formats for Processing. If a file has been successfully selected, continues with a call to loadAudioFile() or loadImageFile().
      Parameters:
      selectedFile - the File the user selected
    • loadAudioFile

      public void loadAudioFile(File audFile)
      Attempts to load audio data from a selected file into playBuffer, then calls writeAudioToImage() to transcode audio data and write it to mapImage. If doResample is true, resamples files whose sample rate differs from the current audio output. If you want to load the image file and audio file separately, comment out writeAudioToImage().
      Parameters:
      audFile - an audio file
    • loadImageFile

      public void loadImageFile(File imgFile)
      Attempts to load image data from a selected file into mapImage, then calls writeImageToAudio() to transcode HSB brightness channel to audio and writes it to playBuffer and audioSignal.
      Parameters:
      imgFile - an image file
    • writeAudioToImage

      public void writeAudioToImage(float[] sig, PixelAudioMapper mapper, processing.core.PImage img, PixelAudioMapper.ChannelNames chan)
      Transcodes audio data in sig[] and writes it to color channel chan of mapImage using the lookup tables in mapper to redirect indexing. Calls mapper.mapSigToImg(), which will throw an IllegalArgumentException if sig.length != img.pixels.length or sig.length != mapper.getSize(). We typically use PixelAudioMapper.ChannelNames.ALL or PixelAudioMapper.ChannelNames.L as the chan value. Both result in gray values, with PixelAudioMapper.ChannelNames.L maintaining previous hue and saturation color values in the image.
      Parameters:
      sig - an array of float, should be audio data in the range [-1.0, 1.0]
      mapper - a PixelAudioMapper
      img - a PImage
      chan - a color channel
    • setAlphaWithBlack

      public int setAlphaWithBlack(int argb, int alpha)
      Sets the alpha channel of an RGBA color, conditionally setting alpha = 0 if all other channels = 0.
      Parameters:
      argb - an RGBA color value
      alpha - the desired alpha value to apply to argb
      Returns:
      the argb color with changed alpha channel value
    • setAlpha

      public static int setAlpha(int argb, int alpha)
      Sets the alpha channel of an RGBA color.
      Parameters:
      argb - an RGBA color value
      alpha - the desired alpha value to apply to argb
      Returns:
      the argb color with changed alpha channel value
    • writeImageToAudio

      public void writeImageToAudio(processing.core.PImage img, PixelAudioMapper mapper, float[] sig, PixelAudioMapper.ChannelNames chan, int shift)
      This method writes a color channel from an image to playBuffer, fulfilling a central concept of the PixelAudio library: image is sound. Calls mapper.mapImgToSig(), which will throw an IllegalArgumentException if img.pixels.length != sig.length or img.width * img.height != mapper.getWidth() * mapper.getHeight(). Sets totalShift = 0 on completion: the image and audio are now in sync.
      Parameters:
      img - a PImage, a source of data
      mapper - a PixelAudioMapper, handles mapping between image and audio signal
      sig - a target array of float in audio format
      chan - a color channel
      shift - number of indices to shift
    • renderMapImageToAudio

      public void renderMapImageToAudio(PixelAudioMapper.ChannelNames chan)
      Writes a specified channel of mapImage to audioSignal.
      Parameters:
      chan - the selected color channel
    • commitMapImageToAudio

      public void commitMapImageToAudio()
      Writes mapImage to the audio chain and makes the displayed image the new base image.
    • commitMapImageToBaseImage

      public void commitMapImageToBaseImage()
      Writes the mapImage, which may change with animation, to the baseImage, a reference image that usually only changes when a new file is loaded.
    • commitNewBaseImage

      public void commitNewBaseImage(processing.core.PImage img)
      Copies the supplied PImage to mapImage and baseImage, sets totalShift to 0 (the images are identical).
      Parameters:
      img -
    • refreshMapImageFromBase

      public void refreshMapImageFromBase()
      Writes baseImage to mapImage with an index position offset of totalShift.
    • saveGestureJSON

      void saveGestureJSON(boolean saveSession)
    • jsonFileSelectedWrite

      public void jsonFileSelectedWrite(File jsonFile)
      Save the curve and config data from the current activeBrush.
      Parameters:
      jsonFile - initially, the file to save to (naming conventions may change the full name)
    • saveSessionJSON

      public void saveSessionJSON(File jsonFile)
    • loadGestureJSON

      void loadGestureJSON()
    • jsonFileSelectedRead

      public void jsonFileSelectedRead(File jsonFile)
    • chooseGestureLibraryFolder

      void chooseGestureLibraryFolder()
    • gestureLibraryFolderSelected

      public void gestureLibraryFolderSelected(File folder)
    • initAudio

      public void initAudio()
      CALL THIS METHOD IN SETUP() Initializes Minim audio library and audio variables.
    • initTimedEventLists

      public void initTimedEventLists()
      Initialize lists of TimedLocation objects, used for animated response to mouse clicks on brushstrokes and outside brushstrokes.
    • getSamplePos

      public int getSamplePos(int x, int y)
      Calculates the index of the image pixel within the signal path, taking the shifting of pixels and audioSignal into account. See MusicBoxBuffer for use of a windowed buffer in this calculation.
      Parameters:
      x - an x coordinate within mapImage and display bounds
      y - a y coordinate within mapImage and display bounds
      Returns:
      the index of the sample corresponding to (x,y) on the signal path
    • getCoordFromSignalPos

      public processing.core.PVector getCoordFromSignalPos(int pos)
      Calculates the display image coordinates corresponding to a specified audio sample index.
      Parameters:
      pos - an index into an audio signal, must be between 0 and width * height - 1.
      Returns:
      a PVector with the x and y coordinates
    • runSamplerPointEvent

      void runSamplerPointEvent(int x, int y)
      Plays a sample and animates a point
      Parameters:
      x - x-coordinate of event
      y - y-coordinate of event
    • runSamplerDrawEvent

      void runSamplerDrawEvent(int x, int y)
      Plays a sample and animates a point
      Parameters:
      x - x-coordinate of event
      y - y-coordinate of event
    • runGranularPointEvent

      void runGranularPointEvent(int x, int y)
      Plays a granular burst and animates a point
      Parameters:
      x - x-coordinate of event
      y - y-coordinate of event
    • playGranularGesture

      public void playGranularGesture(float[] buf, GestureSchedule sched, GestureGranularParams params)
      Primary method for playing a granular synthesis audio event.
      Parameters:
      buf - an audio signal as a array of float
      sched - GestureSchedule (points + times) for grains
      params - core parameters for granular synthesis
    • playGranularGesture

      public void playGranularGesture(float[] buf, GestureSchedule sched, GestureGranularParams params, GestureEventParams eventParams)
      Primary method for playing a granular synthesis audio event.
      Parameters:
      buf - an audio signal as a array of float
      sched - GestureSchedule (points + times) for grains
      params - core parameters for granular synthesis
      eventParams - event parameters for granular synthesis
    • prepareGranularGesture

      public GestureEventParams prepareGranularGesture(float[] buf, GestureSchedule sched, GestureGranularParams params)
    • prepareGranularGesture

      public GestureEventParams prepareGranularGesture(float[] buf, GestureSchedule sched, GestureGranularParams params, PAControlCurve gainCurve)
    • generateJitterPitch

      float[] generateJitterPitch(int length, float basePitch, float deviationPitch)
    • calculateEnvelopeDb

      public ADSRParams calculateEnvelopeDb(float gainDb, int totalSamples, float sampleRate)
      Calculate an envelope of length totalSamples.
      Parameters:
      gainDb - desired gain in dB, currently ignored
      totalSamples - number of samples the envelope should cover
      sampleRate - sample rate of the audio buffer the envelope is applied to
      Returns:
      and ADSRParams envelope
    • calculateEnvelopeLinear

      public ADSRParams calculateEnvelopeLinear(float linear, float totalMs)
      Calculate an envelope of length totalSamples.
      Parameters:
      linear - desired gain as a linear ratio, currently ignored
      totalMs - desired duration of the envelope in milliseconds
      Returns:
      an ADSRParams envelope
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, float pan)
      Plays an audio sample with default envelope and stereo pan.
      Parameters:
      samplePos - position of the sample in the audio buffer
      samplelen - length of the sample (will be adjusted)
      amplitude - amplitude of the sample on playback
      pan - stereo pan [-1.0, 1.0] for sample
      Returns:
      the calculated sample length in samples
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pan)
      Plays an audio sample with a custom envelope and stereo pan.
      Parameters:
      samplePos - position of the sample in the audio buffer
      samplelen - length of the sample (will be adjusted)
      amplitude - amplitude of the sample on playback
      env - an ADSR envelope for the sample
      pan - position of sound in the stereo audio field (-1.0 = left, 0.0 = center, 1.0 = right)
      Returns:
      the calculated sample length in samples
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pitch, float pan)
      Plays an audio sample with with a custom envelope, pitch and stereo pan.
      Parameters:
      samplePos - position of the sample in the audio buffer
      samplelen - length of the sample (will be adjusted)
      amplitude - amplitude of the sample on playback
      env - an ADSR envelope for the sample
      pitch - pitch scaling as deviation from default (1.0), where 0.5 = octave lower, 2.0 = oactave higher
      pan - position of sound in the stereo audio field (-1.0 = left, 0.0 = center, 1.0 = right)
      Returns:
      the calculated sample length in samples
    • calcSampleLen

      public int calcSampleLen(int dur, float mean, float variance)
      Parameters:
      dur - sample duration in milliseconds
      mean - multiplier for duration, 1.0 leaves duration as mean value
      variance - variance from mean value
      Returns:
      a length in samples with some Gaussian variation
    • calcSampleLen

      public int calcSampleLen()
      Convenience method for calcSampleLen(envDuration, 1.0f, 0.0625f).
      Returns:
      calculated sample length in samples of an envelope
    • computeEnvDurationMs

      int computeEnvDurationMs(GestureSchedule sched, String envName, int fallbackMs)
      Parameters:
      sched - a GestureSchedule to access for calculating an envelope duration
      envName - name of an envelope preset
      fallbackMs - default duration in milliseconds
      Returns:
      calculated sample length in samples of an envelope
    • ensureSamplerReady

      void ensureSamplerReady()
      Prepares Sampler instruments and assets
    • ensureGranularReady

      void ensureGranularReady()
      Prepares Granular instruments and assets
    • buildGranSynth

      public PAGranularInstrument buildGranSynth(ddf.minim.AudioOutput out, ADSRParams env, int numVoices)
      Initializes a PAGranularInstrument.
      Parameters:
      out - AudioOutput for this application
      env - an ADSRParams envelope
      numVoices - number of voices for the synth
      Returns:
      a PAGranularInstrument
    • initGranularParams

      public void initGranularParams()
      Initializes gParamsFixed, a GestureGranularParams instances used for granular point events.
    • updateAudioChain

      void updateAudioChain(float[] sig, float bufferSampleRate)
      Bottleneck "commit" method for audio state. Takes an arbitrary input signal and installs it as the canonical audio signal used by the system. This method: - Resizes/pads/truncates the input to mapper.getSize() - Copies the data to ensure no external aliasing - Updates audioSignal (canonical signal handled by application code) - Updates playBuffer (audio buffer used by Minim audio library methods) - Propagates the buffer to active instruments: edit this part for your own code This is the ONLY method that should mutate the global audio signal state. In PixelAudio examples, the signal is typically loaded from a file, but it could also be signal cached in memory, a signal generated by code, audio captured live, etc.
      Parameters:
      sig - an audio signal
      bufferSampleRate - audio sample rate for sig, usually obtained when reading from an audio file
    • updateAudioChain

      void updateAudioChain(float[] sig)
    • updateInstrumentLoops

      public void updateInstrumentLoops()
      Updates looping instruments.
    • stopAllLoops

      public void stopAllLoops()
      Stops all loops.
    • stopLoopsForBrush

      public void stopLoopsForBrush(AudioBrush brush)
      Stop looping for a specified brush
      Parameters:
      brush - AudioBrush whose looping will end
    • hasLoopForBrush

      public boolean hasLoopForBrush(AudioBrush brush)
    • estimateLoopDurationMs

      public int estimateLoopDurationMs(GestureSchedule sched, GestureGranularParams params)
      Estimate loop duration for a Granular instrument.
      Parameters:
      sched - a GestureSchedule associated with a brush
      params - a GestureGranularParams object
      Returns:
      expected duration of a loop
    • estimateLoopDurationMs

      public int estimateLoopDurationMs(GestureSchedule sched, ADSRParams env, int noteLenSamples)
      Estimate loop duration for a Sampler instrument.
      Parameters:
      sched - a GestureSchedule associated with a brush
      env - an ADSRParams envelope
      noteLenSamples - number of samples in audio event ("note")
      Returns:
      expected duration of a loop
    • startGranularLoop

      public Bagatelle.InstrumentLoop startGranularLoop(GranularBrush gb, float[] buf, GestureSchedule sched, GestureGranularParams params, GestureEventParams eventParams, int repeats, int gapMs, boolean animate)
      Parameters:
      gb - a GranularBrush to loop
      buf - buffer to play from
      sched - a GestureSchedule
      params - runtime parameters for gesture playback
      eventParams - optional pan, gain, and pitch modifiers per grain
      repeats - number of times to loop
      gapMs - time between loop events
      animate - use TimedLocation animation (not used in method, true by default, TODO clarify)
      Returns:
      an InstrumentLoop object
    • loopGranularBrush

      public Bagatelle.InstrumentLoop loopGranularBrush(GranularBrush gb, int repeats, int gapMs)
      Parameters:
      gb - a GranularBrush
      repeats - number of times to repeat loop
      gapMs - time between repetitions, ms
      Returns:
      an InstrumentLoop object
    • startSamplerLoop

      public Bagatelle.InstrumentLoop startSamplerLoop(SamplerBrush sb, GestureSchedule sched, ADSRParams env, int noteLenSamples, int repeats, int gapMs, boolean animate)
      Parameters:
      sb - a SamplerBrush
      sched - GestureSchedule for brush events
      env - ADSRParams envelope for each Sampler event in schedule
      noteLenSamples - length of a note in samples
      repeats - number of times to repeat loop
      gapMs - time between loop repetitions, ms
      animate - use TimedLocation animation (not used in method, true by default, TODO clarify)
      Returns:
      an InstrumentLoop object
    • loopSamplerBrush

      public Bagatelle.InstrumentLoop loopSamplerBrush(SamplerBrush sb, int repeats, int gapMs)
      Parameters:
      sb - a SamplerBrush instance
      repeats - number of times to repeat
      gapMs - time between loop repetitions, ms
      Returns:
    • applyColor

      public int[] applyColor(int[] colorSource, int[] graySource, int[] lut)
      Utility method for applying hue and saturation values from a source array of RGB values to the brightness values in a target array of RGB values, using a lookup table to redirect indexing.
      Parameters:
      colorSource - a source array of RGB data from which to obtain hue and saturation values
      graySource - a target array of RGB data from which to obtain brightness values
      lut - a lookup table, must be the same size as colorSource and graySource
      Returns:
      the graySource array of RGB values, with hue and saturation values changed
      Throws:
      IllegalArgumentException - if array arguments are null or if they are not the same length
    • applyColorShifted

      public int[] applyColorShifted(int[] colorSource, int[] graySource, int[] lut, int shift)
      Utility method for applying hue and saturation values from a source array of RGB values to the brightness values in a target array of RGB values, using a lookup table to redirect indexing, taking into account any pixels that were shifted.
      Parameters:
      colorSource - a source array of RGB data from which to obtain hue and saturation values
      graySource - a target array of RGB data from which to obtain brightness values
      lut - a lookup table, must be the same size as colorSource and graySource
      shift - pixel shift from array rotation, windowed buffer, etc.
      Returns:
      the graySource array of RGB values, with hue and saturation values changed
      Throws:
      IllegalArgumentException - if array arguments are null or if they are not the same length
    • applyColorMap

      public void applyColorMap()
      Applies the Hue and Saturation of pixel values in the colors[] array to mapImage and baseImage.
    • initAllPoints

      public void initAllPoints()
      Initializes allPoints and adds the current mouse location to it.
    • handleClickOutsideBrush

      public int handleClickOutsideBrush(int x, int y)
      Respond to mousePressed events, usually by triggering an event
    • handlePlayOnDraw

      void handlePlayOnDraw(int x, int y)
      Dispatches lightweight "taste" audio while drawing. Call this only after a new drawing point has been accepted.
    • shouldTriggerDrawTaste

      boolean shouldTriggerDrawTaste(int x, int y, int nowMs)
      Shared thinning logic for draw-time tasting. Requires both: 1) enough time since the last taste 2) enough mouse movement since the last taste point
    • runSamplerDrawTaste

      void runSamplerDrawTaste(int x, int y)
      Lightweight Sampler "taste" while drawing. Short, percussive, cheap to trigger.
    • runGranularDrawTaste

      void runGranularDrawTaste(int x, int y)
      Lightweight Granular "taste" while drawing. Uses a very small fixed-hop burst gesture so the result is textured but inexpensive compared to full gesture playback.
    • isOverAnyBrush

      boolean isOverAnyBrush(int x, int y)
    • addDrawingPoint

      public void addDrawingPoint(int x, int y)
      While user is dragging the mouse and mode == Mode.DRAW_EDIT_GRANULAR or DRAW_EDIT_SAMPLER, accumulates new points to allPoints and event times to allTimes. Coordinates should be constrained to display window bounds.
      Parameters:
      x - x-coordinate
      y - y-coordinate
    • clipToWidth

      public int clipToWidth(int x)
      Parameters:
      x - a value to constrain to the current window width
      Returns:
      the constrained value
    • clipToHeight

      public int clipToHeight(int y)
      Parameters:
      y - a value to constrain to the current window height
      Returns:
      the constrained value
    • jitterCoord

      public processing.core.PVector jitterCoord(int x, int y, int deviationPx)
      Displaces a supplied point by a random Gaussian variable.
      Parameters:
      x - x-coordinate
      y - y-coordinate
      deviationPx - average deviation, in pixels
      Returns:
      a displaced coordinate point as a PVector
    • loadGestureSchedule

      public GestureSchedule loadGestureSchedule(PACurveMaker brush, GestureGranularConfig snap)
      Builds a GestureSchedule for a PACurveMaker brush and a snapshot of a GestureGranularConfig
      Parameters:
      brush - a PACurveMaker brush
      snap - a snapshot of a GestureGranularConfig
      Returns:
      a GestureSchedule
    • initCurveMakerAndAddBrush

      public AudioBrush initCurveMakerAndAddBrush()
      Initializes a PACurveMaker instance with allPoints as an argument to the factory method PACurveMaker.buildCurveMaker() and then fills in PACurveMaker instance variables.
    • makeBrushFromCurveMaker

      public AudioBrush makeBrushFromCurveMaker()
      Returns:
      an AudioBrush generated from the current GUI configuration and PACurveMaker object curveMaker.
    • makeBrush

      public AudioBrush makeBrush(PACurveMaker curve, GestureGranularConfig.Builder config)
      Parameters:
      curve - a PACurveMaker instance
      config - a GestureGranularConfig.Builder
      Returns:
      an AudioBrush generated from the supplied GestureGranularConfig and PACurveMaker
    • makeBrush

      End point for all makeBrush(...) calls, applies cues and special fx.
      Parameters:
      curve -
      config -
      instrumentType -
      Returns:
    • applyPerformancePresets

      public Bagatelle.CueResult applyPerformancePresets(GestureGranularConfig.Builder cfg, PACurveMaker curve)
      Apply performance presets from the stack associated with the current performance mode.
      Parameters:
      cfg - audio and curve configuration
      curve - PACurveMaker instance for brush
      Returns:
      gesture and audio configuration determined by preset
    • applyAJPresets

      public Bagatelle.CueResult applyAJPresets(GestureGranularConfig.Builder cfg, PACurveMaker curve)
      Apply a performance preset from aj_presetStack, for "Abstract Jailbreak" performance.
      Parameters:
      cfg - audio and curve configuration
      curve - PACurveMaker instance for brush
      Returns:
      gesture and audio configuration determined by preset
    • applyDBWFPresets

      public Bagatelle.CueResult applyDBWFPresets(GestureGranularConfig.Builder cfg, PACurveMaker curve)
      Apply a performance preset from dbwf_presetStack, for "DEADBODYWORKFLOW" performance.
      Parameters:
      cfg - audio and curve configuration
      curve - PACurveMaker instance for brush
      Returns:
      gesture and audio configuration determined by preset
    • isBrushInteractable

      boolean isBrushInteractable(AudioBrush b)
      Parameters:
      b - an AudioBrush instance
      Returns:
      return true if brush aligns with current drawingMode
    • setActiveBrush

      void setActiveBrush(AudioBrush brush)
      Assigns a brush to be the current active brush, accessible for editing and other options.
      Parameters:
      brush - an AudioBrush to assign
    • setActiveBrush

      void setActiveBrush(AudioBrush brush, int idx)
      Assigns a brush to be the current active brush, accessible for editing and other options.
      Parameters:
      brush - an AudioBrush to assign
      idx - index with a list of brushes of a particular type
    • recomputeUIBaselinesFromActiveBrush

      void recomputeUIBaselinesFromActiveBrush()
      Caching for UI settings, may be superfluous.
    • drawBrushShapes

      public void drawBrushShapes()
      Draws brushes in available brush lists, calls drawBrushes(List<? extends AudioBrush>, int, int, int), passing each list and colors for flagging its UI status.
    • drawBrushes

      public void drawBrushes(List<? extends AudioBrush> brushes, int readyColor, int hoverColor, int selectedColor)
      Iterates over a brush list and draws the brushstrokes stored in each PACurveMaker in the list.
      Parameters:
      brushes -
      readyColor -
      hoverColor -
      selectedColor -
    • getPathPoints

      ArrayList<processing.core.PVector> getPathPoints(AudioBrush b)
      Provides the list of points for a brush in its assigned PathMode representation.
      Parameters:
      b - an AudioBrush
      Returns:
      points in the path associated with the brush, as a list of PVector
    • getScheduleForBrush

      public GestureSchedule getScheduleForBrush(AudioBrush b)
      Provides the times associated with a brush in its assigned PathMode representation.
      Parameters:
      b - an AudioBrush instance
      Returns:
      GestureSchedule for the current pathMode of the brush
    • getPlaybackScheduleForBrush

      GestureSchedule getPlaybackScheduleForBrush(AudioBrush b)
      Provides a GestureSchedule associated with a brush, applying the boundsPolicy to bring all points in bounds.
      Parameters:
      b - an AudioBrushLIte instance
      Returns:
      a GestureSchedule filtered by boundsPolicy to provide only in-bounds points
    • initBrushTransform

      void initBrushTransform(AudioBrush b)
      Initializes a brush to apply a geometric transform.
      Parameters:
      b - an AudioBrush instance
    • updateAnimatedBrushes

      void updateAnimatedBrushes()
      Test code to apply a geometric transform to the active brush, a form of animation when repeatedly applied over time.
    • mouseInPoly

      public boolean mouseInPoly(ArrayList<processing.core.PVector> poly)
      Parameters:
      poly - a polygon described by an ArrayList of PVector
      Returns:
      true if the mouse is within the bounds of the polygon, false otherwise
    • pointInPoly

      public boolean pointInPoly(ArrayList<processing.core.PVector> poly, int x, int y)
      Parameters:
      poly - a polygon described by an ArrayList of PVector
      x - x-coordinate
      y - y-coordinate
      Returns:
      true if the mouse is within the bounds of the polygon, false otherwise
    • reset

      public void reset(boolean isClearCurves)
      Reinitializes audio and clears event lists. If isClearCurves is true, clears brushShapesList. There's no key command to trigger this, yet. TODO decide if you want a key command.
      Parameters:
      isClearCurves -
    • removeActiveBrush

      public void removeActiveBrush()
      Removes the current active PACurveMaker instance, flagged by a highlighted brush stroke, from brushShapesList, if there is one.
    • removeHoverBrush

      public void removeHoverBrush()
      Removes the current active PACurveMaker instance, flagged by a highlighted brush stroke, from brushShapesList, if there is one.
    • removeNewestBrush

      public void removeNewestBrush()
      Removes the newest PACurveMaker instance, shown as a brush stroke in the display, from brushShapesList.
    • removeOldestBrush

      public void removeOldestBrush()
      Removes the oldest brush in brushShapesList.
    • toggleBrushType

      AudioBrush toggleBrushType(AudioBrush brush)
      Convert a brush to the opposite type, reusing the same PACurveMaker and the same GestureGranularConfig.Builder instance. This is a replacement operation: the old brush should be removed from its list immediately after conversion.
      Parameters:
      brush - AudioBrush to convert, GranularBrush to/from SamplerBrush
    • toSamplerBrush

      SamplerBrush toSamplerBrush(AudioBrush brush)
      Convert a brush explicitly to SamplerBrush.
      Parameters:
      brush - an AudioBrush instance
      Returns:
      the brush reconfigured as a SamplerBrush
    • toGranularBrush

      GranularBrush toGranularBrush(AudioBrush brush)
      Convert a brush explicitly to GranularBrush.
      Parameters:
      brush - an AudioBrush instance
      Returns:
      the brush reconfigured as a GranularBrush
    • replaceBrush

      void replaceBrush(AudioBrush oldBrush, AudioBrush newBrush, int oldIndex)
      Remove oldBrush from its current typed list, insert newBrush into the opposite typed list, and preserve hover/active state. oldIndex should be the index in the old brush's own list.
    • appendGranularBrush

      int appendGranularBrush(GranularBrush gb)
      Append a granular brush and return its new index.
      Parameters:
      gb - a GranularBrush instance
      Returns:
      the index of the brush in the granularBrushes list
    • appendSamplerBrush

      int appendSamplerBrush(SamplerBrush sb)
      Append a sampler brush and return its new index.
      Parameters:
      sb - a SamplerBrush instance
      Returns:
      the index of the brush in the samplerBrushes list
    • removeGranularBrush

      void removeGranularBrush(AudioBrush gb, int idx)
      Remove a granular brush using index when reliable, else by object.
      Parameters:
      gb - an AudioBrush expected to be a GranularBrush
      idx - index in the granular brush list, or a negative value when unknown
    • removeSamplerBrush

      void removeSamplerBrush(AudioBrush sb, int idx)
      Remove a sampler brush using index when reliable, else by object.
      Parameters:
      sb - an AudioBrush expected to be a SamplerBrush
      idx - index in the sampler brush list, or a negative value when unknown
    • normalizeConfigForSampler

      void normalizeConfigForSampler(GestureGranularConfig.Builder cfg)
      Normalize config values when converting to SamplerBrush. Keep most gesture/path information intact.
      Parameters:
      cfg - a GestureGranularConfig.Builder instance
    • normalizeConfigForGranular

      void normalizeConfigForGranular(GestureGranularConfig.Builder cfg)
      Normalize config values when converting to GranularBrush. Keep most gesture/path information intact, but make a few granular-friendly adjustments.
      Parameters:
      cfg - a GestureGranularConfig.Builder instance
    • toggleHoveredBrushType

      AudioBrush toggleHoveredBrushType()
      Toggle the currently hovered brush between SamplerBrush and GranularBrush.
    • toggleActiveBrushType

      AudioBrush toggleActiveBrushType()
      Toggle the currently active brush between SamplerBrush and GranularBrush.
    • syncDrawingModeToBrush

      void syncDrawingModeToBrush(AudioBrush brush)
      Change the current DrawingMode to suit the brush passed as an argument.
      Parameters:
      brush - an AudioBrush instance
    • scheduleSamplerBrushClick

      void scheduleSamplerBrushClick(SamplerBrush sb, int clickX, int clickY)
      Schedule a simple animation to mark the activation of Sampler audio events at display locations.
      Parameters:
      sb - a SamplerBrush instance
      clickX - x-coordinate
      clickY - y-coordinate
    • scheduleSamplerBrushClick

      void scheduleSamplerBrushClick(SamplerBrush sb, int clickX, int clickY, PAControlCurve gainCurve)
      Schedule a simple animation to mark the activation of Sampler audio events at a display locations.
      Parameters:
      sb - a SamplerBrush instance
      clickX - x-coordinate
      clickY - y-coordinate
      gainCurve - PAControlCurve for gain dynamics
    • debugSched

      void debugSched(GestureSchedule sched)
    • storeSamplerBrushEvents

      public void storeSamplerBrushEvents(GestureSchedule sched, GestureGranularConfig snap, int startTime, PAControlCurve gainCurve)
      Adds audio/animation events to samplerBrushEvents
      Parameters:
      sched - schedule of audio/animation events
      snap - snapshot of audio and curve configuration settings
      startTime - time to start events, milliseconds
      gainCurve - optional control curve for gain dynamics
    • runSamplerBrushEvents

      public void runSamplerBrushEvents()
      Runs sampler brush events in the samplerTimeLocs list.
    • scheduleGranularBrushClick

      public void scheduleGranularBrushClick(GranularBrush gb, int clickX, int clickY)
      Convenience method when gain dynamics are not applied to a brush.
      Parameters:
      gb - a GranularBrush
      clickX - x-coordinate of point of activation
      clickY - y-coordinate of point of activation
    • scheduleGranularBrushClick

      public void scheduleGranularBrushClick(GranularBrush gb, int clickX, int clickY, PAControlCurve gainCurve)
      Schedules a response to a mouse click or hover + spacebar on a granular brush.
      Parameters:
      gb - a GranularBrush
      clickX - x-coordinate of point of activation
      clickY - y-coordinate of point of activation
      gainCurve - a control curve for gain dynamics
    • storeGranularCurveTL

      public void storeGranularCurveTL(GestureSchedule sched, int startTime, boolean isGesture)
      Stores granular gesture time/location events in grainTimeLocs.
      Parameters:
      sched - a GestureSchedule, the times when things happen and where they happen
      startTime - time when a gesture starts
      isGesture - is the timing gesture-based or fixed? ignored, for now
    • runGrainEvents

      public void runGrainEvents()
      Tracks and runs TimedLocation events in the grainLocsArray list, which is associated with granular synthesis gestures.
    • runPointEvents

      public void runPointEvents()
      Tracks and runs TimedLocation events in the timeLocsArray list, which is associated with mouse clicks that trigger audio a the click point.
    • pointTimeLocsAddPoint

      public void pointTimeLocsAddPoint(TimedLocation tl)
      Adds a TimedLocation to the pointTimeLocs list.
      Parameters:
      tl - a TimedLocation
    • drawCircle

      public void drawCircle(int x, int y)
      Draws a circle at the location of an audio trigger (mouseDown event).
      Parameters:
      x - x coordinate of circle
      y - y coordinate of circle
    • getPApplet

      public processing.core.PApplet getPApplet()
      Specified by:
      getPApplet in interface PANetworkClientINF
    • getMapper

      public PixelAudioMapper getMapper()
      Specified by:
      getMapper in interface PANetworkClientINF
    • controlMsg

      public void controlMsg(String control, float val)
      Specified by:
      controlMsg in interface PANetworkClientINF
    • playSample

      public int playSample(int samplePos)
      Specified by:
      playSample in interface PANetworkClientINF
    • playPoints

      public void playPoints(ArrayList<processing.core.PVector> pts)
      Specified by:
      playPoints in interface PANetworkClientINF
    • createGUI

      public void createGUI()
      Create all the GUI controls.
    • createControlWindow

      public void createControlWindow()
      Create a separate window for the GUI control palette.
    • createControlPanel

      public void createControlPanel()
      Create the GUI control palette.
    • createCommentsField

      public void createCommentsField()
    • createControls

      public void createControls()
      Create all the controls in the control palette.
    • addControlsToPanel

      public void addControlsToPanel()
      Add the controls to the control palette.
    • winDraw

      public void winDraw(processing.core.PApplet appc, g4p_controls.GWinData data)
    • isGuiTyping

      boolean isGuiTyping()
    • winKey

      public void winKey(processing.core.PApplet appc, g4p_controls.GWinData data, processing.event.KeyEvent evt)
    • controlPanel_hit

      public void controlPanel_hit(g4p_controls.GPanel source, g4p_controls.GEvent event)
    • allOption_clicked

      public void allOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • rdpOption_clicked

      public void rdpOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • curveOption_clicked

      public void curveOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • rdpEpsilonSlider_changed

      public void rdpEpsilonSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • curvePointsSlider_changed

      public void curvePointsSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • gestureOption_clicked

      public void gestureOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • fixedOption_clicked

      public void fixedOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • burstSlider_changed

      public void burstSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • resampleSlider_changed

      public void resampleSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • durationSlider_changed

      public void durationSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • grainLengthSlider_changed

      public void grainLengthSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • hopLengthSlider_changed

      public void hopLengthSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • grainLengthField_changed

      public void grainLengthField_changed(g4p_controls.GTextField source, g4p_controls.GEvent event)
    • hopLengthField_changed

      public void hopLengthField_changed(g4p_controls.GTextField source, g4p_controls.GEvent event)
    • pitchShiftText_changed

      public void pitchShiftText_changed(g4p_controls.GTextField source, g4p_controls.GEvent event)
    • gainSlider_changed

      public void gainSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • linearWarpOption_clicked

      public void linearWarpOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • expWarpOption_clicked

      public void expWarpOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • squareRootOption_clicked

      public void squareRootOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • customWarpOption_clicked

      public void customWarpOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • warpSlider_changed

      public void warpSlider_changed(g4p_controls.GSlider source, g4p_controls.GEvent event)
    • arcLengthTimeOption_clicked

      public void arcLengthTimeOption_clicked(g4p_controls.GOption source, g4p_controls.GEvent event)
    • envelopeMenu_clicked

      public void envelopeMenu_clicked(g4p_controls.GDropList source, g4p_controls.GEvent event)
    • printGConfigStatus

      public void printGConfigStatus()
    • envPreset

      static ADSRParams envPreset(String name)
      Parameters:
      name - the name of the ADSRParams envelope to return
      Returns:
      the specified ADSRParams envelope
    • nearlyEqual

      static boolean nearlyEqual(float a, float b)
    • envEquals

      static boolean envEquals(ADSRParams a, ADSRParams b)
    • envNameFor

      String envNameFor(ADSRParams env)
    • envMenuIndex

      int envMenuIndex(String name)
    • formatEnv

      String formatEnv(ADSRParams env)
    • quantizeToStep

      public static int quantizeToStep(int value, int step)
      Quantize an integer to the nearest multiple of step.
    • syncGuiFromConfig

      void syncGuiFromConfig()
      Synchronize the control palette knobs to the current gConfig, probably because a brush was selected and made active.
    • syncEnvelopeMenu

      void syncEnvelopeMenu(ADSRParams env)
    • findCustomIndex

      int findCustomIndex()
    • clampInt

      static int clampInt(int v, int lo, int hi)
    • setControlsEnabled

      void setControlsEnabled()
      Determine which controls to enable, based on the drawing mode.
    • isEditable

      boolean isEditable()
    • resetConfigToDefaults

      void resetConfigToDefaults()
    • printGOptHints

      void printGOptHints(float alpha)
      Print suggested values for optimizing grain overlap for a brush.
      Parameters:
      alpha -
    • calcGranularOptHints

      public int calcGranularOptHints(String tag, int N, float Tms, int hopSamples, int grainLenSamples, float sr, List<processing.core.PVector> scheduledPoints, float targetSpacingPx, float wt, float ws, StringBuffer sb)
      Calculate optimal configuration settings for a granular brush.
      Returns:
      optimal number of samples if time duration is kept as is
    • fmt

      static String fmt(float v, int decimals)