Package net.paulhertz.pixelaudio

# Class WaveSynthBuilder

java.lang.Object
net.paulhertz.pixelaudio.WaveSynthBuilder

public class WaveSynthBuilder extends Object
Utilities for generating WaveSynth "instruments" and working with WaveSynth data. TODO piano key methods and semitoneFac are in AudioUtility, maybe access them from here...

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static int`
  `animSteps`
  `static final double`
  `semitoneFac`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WaveSynthBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `capturePhaseValues(WaveSynth wavesynth)`
  Applies the current phase values to the initial values of the WaveSynth, so that the current state of the image display will appear as the first frame of animation.
  `static boolean`
  `checkJSONHeader(processing.data.JSONObject json, String key, String val)`
  `static float[]`
  `chromaticScale(float funda)`
  `static int`
  `colorShift(int c, float shift)`
  Moves an RGB color into the HSB color space and shifts it by a decimal fraction in the range (0.0,1.0) that represents a portion of the circle of hue values.
  `static float`
  `frequencyPianoKey(float freq)`
  `static boolean`
  `getJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth)`
  `static boolean`
  `getJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth, boolean isStrict)`
  `static processing.data.JSONObject`
  `getWaveSynthJSONHeader()`
  `static void`
  `muteWaveData(WaveSynth wavesynth, int elem)`
  `static float`
  `pianoKeyFrequency(float keyNumber)`
  `static void`
  `printWDStates(ArrayList<WaveData> waveDataList)`
  Prints mute/active status of WaveData operators in supplied waveDataList.
  `static void`
  `saveWaveSynthJSON(processing.core.PApplet app, File selection, WaveSynth synth)`
  `static void`
  `scaleAmps(ArrayList<WaveData> waveDataList, float scale, boolean isVerbose)`
  Scales the amplitude of an ArrayList of WaveData objects.
  `static void`
  `scaleFreqs(ArrayList<WaveData> waveDataList, float scale, boolean isVerbose)`
  Scales the frequencies of an ArrayList of WaveData objects.
  `static void`
  `setWaveSynthFromJSON(processing.data.JSONObject json, WaveSynth synth)`
  Sets the fields of a WaveSynth using values stored in a JSON object.
  `static void`
  `shiftColors(ArrayList<WaveData> waveDataList, float shift, boolean isVerbose)`
  Shifts the colors of an ArrayList of WaveData objects.
  `static void`
  `shiftPhases(ArrayList<WaveData> waveDataList, float shift, boolean isVerbose)`
  Shifts the phase of an ArrayList of WaveData objects.
  `static void`
  `showPhaseValues(WaveSynth wavesynth)`
  Outputs the phase values of a WaveSynth's array of WaveData objects to the console.
  `static ArrayList<WaveData>`
  `synthDoubleStop(float funda1, float funda2, float pianoKey1, float pianoKey2, int animSteps)`
  Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.
  `static ArrayList<WaveData>`
  `synthTrumpet(float fundamental, int howManyPartials, float pianoKey, int animSteps)`
  Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.
  `static void`
  `toggleWDMute(WaveSynth wavesynth, int elem)`
  Mutes or unmutes a WaveData operator (view in the control panel).
  `static void`
  `toggleWDSolo(WaveSynth wavesynth, int elem, boolean isSolo)`
  Sets a specified WaveData element in the waveDataList of a supplied WaveSynth to WaveData.WaveState.SOLO if isSolo is true, otherwise sets it to WaveData.WaveState.ACTIVE.
  `static void`
  `unmuteAllWD(ArrayList<WaveData> waveDataList)`
  Unmutes all the operators in supplied waveDataList.
  `static void`
  `unmuteWaveData(WaveSynth wavesynth, int elem)`
  `static String`
  `waveSynthAsString(WaveSynth synth)`
  Returns supplied WaveSynth settings and WaveData list as a formated String.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### semitoneFac

    public static final double semitoneFac

  - ### animSteps

    public static int animSteps

- ## Constructor Details

  - ### WaveSynthBuilder

    public WaveSynthBuilder()

- ## Method Details

  - ### synthTrumpet

    public static ArrayList<WaveData> synthTrumpet(float fundamental, int howManyPartials, float pianoKey, int animSteps)
    Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.
    Returns:
      an ArrayList of WaveData objects

  - ### synthDoubleStop

    public static ArrayList<WaveData> synthDoubleStop(float funda1, float funda2, float pianoKey1, float pianoKey2, int animSteps)
    Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.
    Returns:
      an ArrayList of WaveData objects

  - ### chromaticScale

    public static float[] chromaticScale(float funda)

  - ### pianoKeyFrequency

    public static float pianoKeyFrequency(float keyNumber)

  - ### frequencyPianoKey

    public static float frequencyPianoKey(float freq)

  - ### colorShift

    public static int colorShift(int c, float shift)
    Moves an RGB color into the HSB color space and shifts it by a decimal fraction in the range (0.0,1.0) that represents a portion of the circle of hue values. For example, 1.0f/24 is 15 degrees around the 360-degree HSB color circle.
    Parameters:
      `c` - an RGB color
      `shift` - the shift [0..1] of the hue in the HSB representation of color c
    Returns:
      the RGB representation of the shifted color

  - ### scaleAmps

    public static void scaleAmps(ArrayList<WaveData> waveDataList, float scale, boolean isVerbose)
    Scales the amplitude of an ArrayList of WaveData objects.
    Parameters:
      `waveDataList` - an ArrayList of WaveData objects
      `scale` - the amount to scale the amplitude of each WaveData object
      `isVerbose` - if true, output changes to data to the console

  - ### shiftColors

    public static void shiftColors(ArrayList<WaveData> waveDataList, float shift, boolean isVerbose)
    Shifts the colors of an ArrayList of WaveData objects.
    Parameters:
      `waveDataList` - an ArrayList of WaveData objects
      `shift` - the amount shift each color
      `isVerbose` - if true, output changes to data to the console

  - ### scaleFreqs

    public static void scaleFreqs(ArrayList<WaveData> waveDataList, float scale, boolean isVerbose)
    Scales the frequencies of an ArrayList of WaveData objects.
    Parameters:
      `waveDataList` - an ArrayList of WaveData objects
      `scale` - the amount to scale the frequency of each WaveData object
      `isVerbose` - if true, output changes to data to the console

  - ### shiftPhases

    public static void shiftPhases(ArrayList<WaveData> waveDataList, float shift, boolean isVerbose)
    Shifts the phase of an ArrayList of WaveData objects.
    Parameters:
      `waveDataList` - an ArrayList of WaveData objects
      `shift` - amount to shift the phase of each WaveData object
      `isVerbose` - if true, output changes to data to the console

  - ### showPhaseValues

    public static void showPhaseValues(WaveSynth wavesynth)
    Outputs the phase values of a WaveSynth's array of WaveData objects to the console.
    Parameters:
      `wavesynth` - a WaveSynth whose waveDataList's phase values will be output

  - ### capturePhaseValues

    public static void capturePhaseValues(WaveSynth wavesynth)
    Applies the current phase values to the initial values of the WaveSynth, so that the current state of the image display will appear as the first frame of animation. Save the WaveSynth to a JSON file to keep the new phase values.
    Parameters:
      `wavesynth` - an WaveSynth whose current WaveData phase values will be captured

  - ### toggleWDMute

    public static void toggleWDMute(WaveSynth wavesynth, int elem)
    Mutes or unmutes a WaveData operator (view in the control panel).
    Parameters:
      `wavesynth` - a WaveSynth
      `elem` - the index number of a WaveData object stored in a WaveSynth's waveDataList field

  - ### muteWaveData

    public static void muteWaveData(WaveSynth wavesynth, int elem)

  - ### unmuteWaveData

    public static void unmuteWaveData(WaveSynth wavesynth, int elem)

  - ### unmuteAllWD

    public static void unmuteAllWD(ArrayList<WaveData> waveDataList)
    Unmutes all the operators in supplied waveDataList.
    Parameters:
      `waveDataList` - an ArrayList of WaveData objects

  - ### toggleWDSolo

    public static void toggleWDSolo(WaveSynth wavesynth, int elem, boolean isSolo)
    Sets a specified WaveData element in the waveDataList of a supplied WaveSynth to WaveData.WaveState.SOLO if isSolo is true, otherwise sets it to WaveData.WaveState.ACTIVE. If isSolo is true, all other WaveData elements taht are ACTIVE will be set to SUSPENDED. Any elements that are currently muted will remain muted, any elements whose waveState is SOLO will remain unchanged. Call unmuteAllWD() to set all elements to ACTIVE. TODO improve on the logic for WaveState changes.
    Parameters:
      `wavesynth` - a WaveSynth whose waveDataList will be affected
      `elem` - index of an element in the waveDataList
      `isSolo` - if true, set WaveData element to WaveData.WaveState.SOLO otherwise, set it to WaveData.WaveState.ACTIVE

  - ### printWDStates

    public static void printWDStates(ArrayList<WaveData> waveDataList)
    Prints mute/active status of WaveData operators in supplied waveDataList.
    Parameters:
      `waveDataList` - an ArrayList of WaveData objects

  - ### getJSONFromFile

    public static boolean getJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth, boolean isStrict)
    Parameters:
      `selection` - a file containing JSON data
      `json` - a JSONObject that will be initialized with data from the file
      `synth` - a WaveSynth object whose fields will be filled out from the JSON data
      `isStrict` - if true, return false if no WaveSynth header is found in the JSON file
    Returns:
      true if the File

  - ### getJSONFromFile

    public static boolean getJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth)

  - ### checkJSONHeader

    public static boolean checkJSONHeader(processing.data.JSONObject json, String key, String val)

  - ### setWaveSynthFromJSON

    public static void setWaveSynthFromJSON(processing.data.JSONObject json, WaveSynth synth)
    Sets the fields of a WaveSynth using values stored in a JSON object.
    Parameters:
      `json` - a JSON object, typically read in from a file
      `synth` - a WaveSynth

  - ### waveSynthAsString

    public static String waveSynthAsString(WaveSynth synth)
    Returns supplied WaveSynth settings and WaveData list as a formated String.

  - ### saveWaveSynthJSON

    public static void saveWaveSynthJSON(processing.core.PApplet app, File selection, WaveSynth synth)

  - ### getWaveSynthJSONHeader

    public static processing.data.JSONObject getWaveSynthJSONHeader()