Sie sind auf Seite 1von 25

CMPO 211

C R E ATIV E P ROJECTS IN IN TER ACTI VE SONI C ART S

Lecture 8.2: MIDI, text, list operations, presentation mode


Michael Norris michael.norris@nzsm.ac.nz

TODAY

Working with MIDI

Working with, and parsing, text

User text input

List operations

Text-to-MIDI converter!

SELECTING A MIDI DEVICE

MIDI information can be generated, or received from an input device

MIDI information can be output to an output device

Note: a MIDI device can have up to 16 MIDI instruments attached to it

each instrument is referenced by a channel number

SELECTING A MIDI DEVICE

midiinfo umenu

bang in left inlet populates umenu with output devices

bang in right inlet populates umenu with input devices

umenu outputs selected item number out leftmost outlet, and the chosen item
text out middle outlet

Will mostly use 2nd outlet of the umenu, the chosen device name

NB: always good to provide both a loadbang, and a refresh MIDI devices
textbutton, so that MIDI devices can be added arbitrarily

RECEIVING MIDI DATA

The midiin object outputs raw MIDI data as it is received

Raw MIDI data includes note ons, note offs, controller data, timing/sync
data, etc.

Spat out as a series of numbers

However, this is pretty hard to work with and unhelpful

Max is bundled with helper objects to make MIDI easier to deal with

RECEIVING MIDI NOTES

notein only listens to NOTE-SPECIFIC MIDI INFORMATION

notein outputs three items of data:

PITCH (as a MIDI note number from 0 to 127 use mtof to convert to

frequency, or scale to change to some other range)

VELOCITY (from 1127 for loudness, or 0 for note off)

MIDI CHANNEL (that tells you which MIDI instrument sent the message)

RECEIVING MIDI CONTROLLER DATA

ctlin is like notein, but only for controller information (e.g. an external MIDI
controller)

Outputs

CONTROL VALUE (0127)

CONTROLLER NUMBER

MIDI CHANNEL (015)

demo: Korg nanocontroller

RECEIVING MIDI CONTROLLER DATA

DEMO: Korg nanoKontrol2

Sends controller values in

How could we use the controller number to route the controller value?

RECEIVING MIDI CONTROLLER DATA

How could we use the controller number to route the controller value?

Use (e.g.) gate 8

nb: gate is 1-based, so well need to add 1 to the controller number

Another supercool way is to dynamically forward the controller value

Use sprintf send ctl%i forward ctl1

PRO TIP: The sprintf object is great because it does true string

concatenation, which append and prepend dont (they append a list item)

SEND MIDI NOTES & CONTROL DATA

To send MIDI information out, we use noteout and ctlout

Remember, however, that you have to send a note-off (0-velocity note


message) after a certain time period

To ease this, Max includes a makenote object which automatically


handles sending the note-off

makenote [velocity] [duration] [channel]

Accepts MIDI pitch in left inlet as integer

10

MIDI SYNTH

Lets make a quick-and-dirty MIDI synth

kslider will be our MIDI note generator

output to AU DLS Synth 1 (this is the built-in OS X MIDI synth PC?)

loadbang midiinfo umenu (outlet 2) noteout

kslider makenote 60 500 (both outlets) noteout

11

TEXT-TO-MIDI CONVERTER

TEXT-TO-MIDI CONVERTER

13

Were going to make a patch that:

Lets the user enter (or copy and paste) some text into a text box

Any letter used (e.g. az) will be mapped to a MIDI pitch, based on a sevennote scale covering almost 4 octaves (7 x 4 = 28, two more than the number
of letters in the alphabet)

The pitches will be output as a kind of rhythm relating to a semiquaver


stream of notes moving through and looping the text, with spaces being
rests

TEXT ENTRY OBJECT

TEXT ENTRY

15

textedit

Attributes:

readonly, keymode (return enters text), lines, fontname, clickmode


(output character/output word), outputmode (list or symbol output?)

Outlets:
1. Text output (as list prepended by text)
2. ASCII value of character typed
3. word/character clicked on
4. textchanged message output when text is changed

GETTING THE TEXT AS A SYMBOL

textedit route text

In properties, set output mode to symbol

Send right outlet t b left inlet

this sends output on every keypress

16

GETTING ASCII VALUES

Now we need to break down this symbol into individual characters

the atoi object converts a symbol into a list of ASCII codes

the itoa object converts a list of ASCII codes into a symbol

route text atoi

17

ASCII is arranged in
blocks of 32

ASCII BASICS
BLOCK 1

(non-printing)

BLOCK 2

(punctuation + numbers)

BLOCK 3

(uppercase letters)

BLOCK 4

(lowercase letters)

032

NON-PRINTING CHARACTERS (return, tab, etc)

32

SPACE character

3347

COMMON PUNCTUATION MARKS (!#$%&()*+,-./)

4857

NUMBERS (09)

5864

MORE PUNCTUATION (:;<=>?@)

6590

UPPERCASE LETTERS (AZ)

9196

RARER PUNCTUATION/accents ([\]^_`)

97122

LOWERCASE LETTERS (az)

123127

RARER PUNCTUATION ({|}~)

18

GETTING LENGTH OF A LIST

Now were going to have a counter that will move through the list of ASCII
codes, pick one out, and convert it into a MIDI note

so we need a: toggle (T) metro 250 counter 0 0

NB: the counter assumes no text to begin with how will we update it
when text is entered?

We need to get the number of items in the atoi list

Let me introduce you to Maxs most powerful object: zl

19

LIST OPERATIONS

LIST OPERATIONS

The zl object lets you create, parse and transform lists in multiple ways

many subobjects that perform different transformations

e.g. zl.scramble randomly redistributes a list

21

OTHER USEFUL LIST FUNCTIONS

zl.join

CONCATENATES two lists

zl.len

COUNTS items in a list

zl.nth

outputs the NTH ITEM of a list

zl.rev

REVERSES a list

zl.rot

ROTATES a list

zl.sort

SORTS a list

zl.sub

SEARCHES for one list in another, and outputs index number

zl.sum

SUMS a list

etc. very rich, many useful functions in here!

22

LIST OPERATIONS

zl example

One common bit of programming inelegance I see is this:

At certain points in the piece, send a different numerical message

Most of you had a sel with lots of arguments, going to multiple


different buttons to multiple different message boxes

There is a better way!

23

LIST OPERATIONS

24

number t b i

rightmost outlet rightmost inlet of zl.sub

leftmost outlet list of ints to match leftmost inlet of zl.sub

zl.sub t b i

rightmost outlet rightmost inlet of zl.nth

leftmost outlet list of ints to choose leftmost inlet of zl.nth

This patch will watch for a match to any of the ints in the message box,
then output a new number from the corresponding list in zl.nth

LIST OPERATIONS

25

To get length of our textedit list, we use zl.len rightmost inlet of counter

To get the nth character of our list, we use zl.mth

PRO TIP: zl.mth is zero-based, zl.nth is one-based

NB: unfortunately zl.mth hot/cold inlets are slightly the wrong way
around text changes in leftmost inlet will immediately output, but we
only want to output when the counter changes, not the text

atoi will only store text sent into rightmost inlet, not output a bang
in leftmost inlet will then output

Das könnte Ihnen auch gefallen