SIGCSE2016 JythonMusicWorkshopSlides Handout
SIGCSE2016 JythonMusicWorkshopSlides Handout
• Introduction
• Music Making
• GUIs
• Image Manipulation
Workshop #102 — SIGCSE 2016
Bill Manaris, College of Charleston • Timer and Scheduling
• Conclusion
1 2
• It is intended for musicians and programmers of all levels • Simple problems != simple programs
and backgrounds.
• Scripting languages (Perl, Python, TCL) designed for simplicity and
• JythonMusic is written in Python (gentle for beginners, flexibility.
powerful enough for experts). • Simple problems = simple, elegant solutions
• It provides libraries for music making, image manipulation, • More amenable to experimentation and incremental development
building graphical user interfaces (GUIs), and for
• Python: Ideal first language, useful throughout curriculum
connecting to external MIDI and OSC devices, such as
digital pianos, smartphones, and tablets. (Quoted from John Zelle, “Teaching Computer Science with Python”, SIGCSE 2003 Workshop)
3 4
Courses CS Principles - 7 Big Ideas
• Creativity - computing is a creative human activity.
• JythonMusic has been used in • Abstraction - helps understand and solve problems.
• CITA 180 / MUSC 146 - “Introduction to Computer • Data and Information - facilitate the creation of knowledge.
Music and Aesthetics: Programming Music, Performing • Algorithms - tools for developing and expressing solutions.
Computers”
• Programming - creative process that produces computational
• HONS 381 - “Computer Music on a Laptop: artifacts.
Composing, Performing, Interacting”
• The Internet - interconnecting devices provide ways to solve
problems.
5 6
bit.ly/CharlestonLaptopOrchestra https://vimeo.com/64110119
7 8
Art Installation - Time Jitters Hyperinstrument #1 - Monterey Mirror
https://vimeo.com/64110119 bit.ly/montereymirror
9 10
• JythonMusic libraries
bit.ly/soundmorpheus1
11 12
Introduction Introduction
• JythonMusic libraries (cont’d) • JythonMusic libraries (cont’d)
• GUI - primitives for building graphical user interfaces • Image - primitives for supporting image sonification
for music performance and other interactive tasks and other types of image manipulation
• MIDI - primitives for connecting to external MIDI • Timer - primitives for scheduling events, such as
devices (e.g., pianos, guitars, synthesizers, etc.) specifying envelope manipulation of audio, as well as
constructing various animation tasks
• OSC - primitives for connecting to other devices via
Open Sound Control (e.g., smartphones, tablets, • Zipf - primitives for extracting measurements from
computers, synthesizers, etc.) musical data
13 14
Running JythonMusic
Programs • JEM (Jython Environment for Music)
• JEM Editor
• Console (>>>)
15 16
• developed and maintained by Tobias Kohn • terminal window (Mac shown below; Windows similar)
17 18
` Outline
• Introduction
• Hello World! — play a single note
• Music Making
• GUIs
• Image Manipulation
• Conclusion
19 20
Note
Music Library
• notes contain the simplest possible musical events,
• The music library defines functions for giving you consisting of pitch, duration, dynamic, and
control and expression over musical parameters panning.
• They are organized in three categories: • pitch (0 - 127, also constants, e.g., C4)
21 22
Note Note
• how to create notes • note functions
23 24
Pitch Pitch Constants
25 26
• 4.0 stands for whole note, 2.0 for a half note, 1.0 for a
quarter note, etc.
27 28
TED Ed - How to read music Activity #2
29 30
Phrase Phrase
• how to create phrases
• phrases contain a sequence of notes
• Notes are played sequentially
• use Rest notes, for gaps
31 32
Phrase Example - Melody
• phrase functions
33 34
.
.
.
35 36
Example - Instrument, Tempo Activity #4
• Change the default instrument. Try a few different
options. Any preferences?
37 38
39 40
Part Part
• how to create parts • part functions
41 42
43 44
Example - Autumn Leaves Drums and Percussion
• MIDI channel 9 reserved for percussion
• Pitch of notes (in phrases) in a part going to channel 9,
determines which percussive instrument to play
• constants available
45 46
47 48
Example - Drum Machine Score
• scores contain parts
49 50
• Mod.repeat(phrase, 41)
51 52
Mod functions Steve Reich - Piano Phase
Mod.repeat() - repeats material
Mod.shift() - changes start time
Mod.retrograde() - reverses notes
Mod.transpose() - changes pitch by number of steps
Mod.elongate() - changes note duration by factor
Mod.invert() - mirrors notes along horizontal axis (a pitch)
Mod.palindrome() - appends the retrograde of the notes
Mod.quantize() - rounds start time and duration of notes
Mod.randomize() - randomly changes note aspects
Mod.fadeIn(), Mod.fadeOut() - as name suggests
Mod.normalize() - maximizes volume (maintain differences)
Mod.compress() - maximizes volume (reduce differences)
…etc.
53 54
55 56
Outline
• Introduction
Midi Library
• Music Making • The MIDI library defines functions for
communicating with MIDI instruments and devices
• MIDI and OSC
• These devices need to be physically connected
• GUIs to your computer
• Image Manipulation • There are two classes: MidiIn, and MidiOut
• Timer and Scheduling • To use these classes, you need:
• Conclusion from midi import *
57 58
midiIn = MidiIn()
59 60
Example MidiIn Program #2
• onNoteOn() connects NOTE_ON events with a
callback function
• channel (0 - 15)
61 62
MidiOut Class
• onInput() connects a particular event type (an
integer) with a callback function
• that function should accept four parameters: • MidiOut objects send MIDI messages to devices (e.g.,
synthesizer) that listen for incoming MIDI events
• event type (an integer) • these devices need to be physically connected (via wire) to
your computer
• channel (0 - 15)
• To create a MidiOut object:
• data1 (an integer, depends on event type) midiOut = MidiOut()
• data2 (an integer, depends on event type) • creates a MidiOut object to send MIDI messages to a device
63 64
Example MidiOut Program Example - Draw Circles via MIDI
65 66
OSC Library
• The OSC (Open Sound Control) library defines
functions for communicating with OSC enabled devices
(e.g., smartphones, tablets, other computers, etc.)
67 68
OscIn Class Example OscIn Program #1
69 70
• very helpful!
71 72
• Notice the special OSC address “/.*”
OscOut Class
• matches all incoming addresses
• OscOut objects send OSC messages to devices (e.g.,
• onInput() uses regular expressions to specify computers) that listen for incoming OSC events
OSC addresses
• To create a OscOut object:
• usually simple OSC addresses suffice, e.g.,
oscOut = OscOut( IPaddress, port )
• “/gyro”
• creates an OscOut object to send messages to
device at IPaddress (a string, e.g., “192.168.1.223”)
• “/accelerometer”, etc.
and port (1024 to 65535)
• also note showMessages() and hideMessages() • again, make sure firewall permits this port (UPD)
73 74
75 76
Outline
• Introduction
GUI Library
• Music Making • The GUI library defines functions for building graphical
user interfaces. They are organized as follows:
• MIDI and OSC
• Display
• GUIs • Widgets: Label, Button, Checkbox, Slider, DropDownList,
TextField, TextArea, Icon, Menu
• Image Manipulation
• Graphics: Line, Circle, Point, Oval, Rectangle, Polygon, Arc
• Timer and Scheduling
• Events: Keyboard Events, Mouse Events, Display Events
• Conclusion • Color
77 78
Display Display
• how to create displays
• to build a GUI, you need at least one display
79 80
Display Graphics
• display functions
• Graphics objects are used to draw various
geometric shapes on a display
• Line
• Circle
• Point
• Oval
• Rectangle
• Polygon
etc.
81 82
etc.
83 84
Example - Button Instrument Play functions
85 86
87 88
AudioSample AudioSample functions
• how to create AudioSamples
89 90
• https://www.freesound.org/
• http://soundbible.com/
91 92
Example - Virtual Piano Outline
• Introduction
• Music Making
• GUIs
• Image Manipulation
• Conclusion
93 94
Image Class
Image Library
95 96
Example - Sonify Image Example - Sonify Image
97 98
Outline
• Introduction
Timer Library
• Music Making
• GUIs
• The timer library defines functions for scheduling
• Image Manipulation tasks (e.g., playing sounds, animation)
• Conclusion
99 100
Timer Class Timer Class
• creates a Timer t, which will call function Play.noteOn(A4) repeatedly every 500
milliseconds (i.e., half second)
101 102
Outline Conclusion
• Introduction • for more info, see
• Music Making
http://jythonmusic.org
• MIDI and OSC
• also see
• GUIs
“Making Music with
• Image Manipulation
Computers: Creative
Programming in Python”,
• Timer and Scheduling
Chapman & Hall/CRC
Textbooks in Computing
• Conclusion
103 104