liveBook · Manning

Musical note

As explained in Learn Haskell by Example

A musical note is a discrete sound event with a defined pitch or rest identity and duration in musical notation.

A musical note identifies a pitched sound and its duration; in a composition, notes can be separated by pauses and arranged sequentially or simultaneously. section 10.4.1 section 11.1

Represent a note at several levels:

  • Use a frequency directly when the synthesizer already has a value in hertz. section 10.4.1
  • Represent pitch as semitone distance from concert A, where 0 means 440 Hz and twelve semitones double the frequency. section 10.4.1
  • Represent named chromatic notes with a note name and octave, then convert them through semitones to frequency. section 10.4.1
  • Place notes inside recursive structures that also contain pauses, sequences, and simultaneous groups. section 11.1

Build and render a melody

A melody can convert chromatic notes to frequencies, render each frequency as a tone, concatenate the events, and write the result to a WAV file: map toFrequency [c 4, e 4, g 4, d 5, c 5]. section 10.4.1

data NoteStructure a
  = Note Notelength a
  | Pause Notelength
  | Sequence [NoteStructure a]
  | Group [NoteStructure a]

Inspect the recursive NoteStructure definition for combining notes, pauses, sequences, and groups. section 11.1

How Learn Haskell by Example covers it

How deep it goes
Explains frequency conversion, chromatic encoding, recursive composition, and concrete rendering, but stops short of heterogeneous structure design.
Examples
Uses concert A at 440 Hz, octave checks, named chromatic notes, recursive compositions, and a rendered melody saved as WAV.
What it assumes
Assumes basic Haskell data types and lists while teaching pitch conversion and recursive composition modeling through implementation.
What you can do after
Build it from scratch as typed pitch values, convert it to frequency, arrange it in compositions, and render playable audio.
How it connects
Connects musical notes with pitch, frequency, semitones, chromatic notes, melodies, chords, pauses, and recursive data structures.

Also explained in

Compare how 3 books explain musical note →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.