1 of 10

Variables, Data Types, and the EarSketch API

2 of 10

What is a variable?

  • A variable is an abstraction inside a program that can hold a value
  • Each variable can only represent one value at a time
    • That value can be a list that in contains multiple values

3 of 10

Variables in EarSketch

  • In this example, there are three variables
    • Each variable is storing the name of a sound constant for various drum sounds (snare, kick, and hi-hat)
  • Note that each of the variables is named after the drum sound associated with it
    • It is important to use meaningful variable names to make code readable and understand what each variable represents

4 of 10

Variables in EarSketch

  • The assignment operator ‘=’ can be used to change the value stored in a variable
  • What is the value of snare on line 9 as it is being referenced by the fitMedia() function?

5 of 10

Variables in EarSketch

  • snare initially stores OS_SNARE01 based on the assignment on line 4, but on line 7 snare is assigned OS_SNARE03
    • The most recent value assigned is the one that is stored
    • Note that the var statement does not need to be used on line 7 since snare has been initialized on a previous line
    • The fitMedia() function on line 9 will use OS_SNARE03 and not OS_SNARE01

6 of 10

Data Types

In JavaScript, there are 8 data types that can be stored in variables

  • It is important to consider what data type will best represent a particular value

  1. Number - a number
  2. BigInt - an integer that is too big to be represented by a Number
  3. String - text
  4. Boolean - TRUE or FALSE
  5. Undefined - a variable that has not been assigned a variable has this type
  6. Null - the lack of an object
  7. Symbol - represents a unique identifier
  8. Object - collections of data

7 of 10

What is EarSketch

EarSketch is a STEAM (science, technology, engineering, arts, and math) learning intervention that combines a programming environment and API for Python and JavaScript, a digital audio workstation, an audio loop library, and a standards-aligned curriculum to teach introductory computer science with music technology and composition.

From the Center of Music Technology - College of Design

8 of 10

The EarSketch API

  • Application Programming Interface (API) is like a software library containing procedures for the selected programming language
  • Using libraries like EarSketch can be helpful when trying to create complex programs for specific purposes
  • Existing code segments can come from internal or external sources, such as libraries or previously written code

9 of 10

The EarSketch API

  • Documentation for the procedures that are part of the EarSketch library is contained in the API (application program interface)
    • Each procedure is broken down in detail: what the parameters are, what each one is used for, etc

10 of 10

Practice

  • Create an EarSketch script with the following:
    • Three different variables, each storing a different sound constant
    • Three function calls of fitMedia() in order to play these sounds in the DAW
      • Reference the EarSketch API to ensure proper usage of fitMedia()