[MUSIC PLAYING]
Earlier in the course, we used a custom Max for Live device
that was really simple.
It just showed what was the last MIDI note that was played.
And it was really handy for tuning our samples.
Now, I think that's a great example of what Max for Live
can be used for-- solving a simple little problem.
And in this video, we're going to build that same device.
And then in following videos, we'll expand on that device
and make a really simple sampler device in Max for Live.
Let's try it out.
Now, Max for Live is a custom programming language.
We call it a graphical programming language that's built into Live.
And you'll find all of the Max devices over here in the Max for Live folder.
We will be making a MIDI Effect.
So I'll open up the Max MIDI Effect folder,
and I'll see the default Max MIDI Effect here.
And I'll drag that into a MIDI track.
Once it's there, we see this really strange interface.
Looks a little different than most devices.
You can kind of see that it's a programming language.
We see we have a comment that says MIDI from Live.
We have this object that says midiin.
Makes sense that that's an input for MIDI.
And we have an object that says midiout, and that kind of makes
sense that it's an output for MIDI.
And there's a cable connecting them.
And that's the general idea with Max is we
have these objects that manipulate data, and they
send data, which we call messages, along cables to other objects.
And so programming in Max is just about knowing
which objects to use, what you're trying to do,
how you're trying to manipulate that MIDI data,
and then sending it along in logical ways.
Now, if I click, I can't edit anything here.
This is fixed and not editable right now.
But there is a Max for Live edit button right here.
If I click that, the Max editor will open up, where we can edit the patch
and develop our MIDI note viewer.
So this does run as a separate application.
But there is a live connection between them.
And so now that we're in the Max editor, I can click on these objects
and I can move them around.
For instance, this is a comment just kind of giving you some information
to build your MIDI effect here.
And I'll take that, and I'll just hit the Delete key, and get rid of it.
We can also start moving objects around now.
I can move this object around.
I can click on this cable, and I could hit the Delete key to get rid of it.
I can click on an output port and drag a cable to an input port.
And if I hover over an output port, it will show me what kind of messages
that object is sending.
If we're careful about what kind of messages were sending and receiving,
we can generate programs this way.
The process of developing any program--
be it Max or another programming language--
is breaking down a complex task into a much smaller, little tasks,
and testing each one of those along the way.
And the first thing we need to make sure that's happening
is MIDI is getting into Max.
And the way we test and visualize the messages moving through Max
is by using the Print Object.
To create a new object, I can go up to the title bar here to this button here,
which says object N.
And I can click on it, and that will create
a new object, where I can start typing to define what kind of object
I want this to be.
I can type in the word Print, and now it's the Print object.
Now, I'm going to delete this and show you a shortcut.
Because we're making objects all the time,
I rarely want to come up here and click on this button.
Notice that the letter N is right next to the word Object.
That means the letter N on your keyboard will generate a new object.
So I can just hit N on my keyboard to make a new object and start typing.
It will even autocomplete to tell us what are
the possible objects with that name.
Now, the idea with Print is anything sent
to its input will be printed into the Max window.
And if you hover over the input port, it will give you some information
about what the object does.
So I will connect the output port of the midiin object
over to the input port of the Print object.
Once I do this, any MIDI that's being received into the Print object
will be printed to the Max console.
And we can find the Max console by going to the right toolbar
here and clicking on this button here for the Max console.
This will print out anything that's going to any Print object.
And you can have many Print objects in your patch.
Now, if I play on my keyboard.
I'm seeing nothing.
And that's a problem.
So let's go back to Live to see if I've done anything wrong.
I'll go to Live, and I notice the problem right away.
My MIDI track is not record enabled.
So I'll record enable it, go back to Max,
and now I'll hit a key on my keyboard.
Now, right when I hit a key on my keyboard, I'm seeing three messages--
144, 62, 86.
When I release a key, I'm seeing a bunch more messages--
128, 62, 0.
Now, I'm really not sure what all those messages mean yet,
but I am seeing I'm getting information into Max, which is awesome.
Again, the process of building a patch, we
must take joy in the little successes because there'll
be a lot of frustrations.
So we have to really enjoy those little things that go right.
As we move on with this patch, we'll have
to divide out or parse this complex MIDI messages.
One of the biggest challenges with Max is finding the right objects.
We have lots and lots of different objects,
and they do many, many amazing things.
But finding the exact right one for your task is one of the hardest challenges.
And so that's where I rely on a lot of Google searches
and also going through all of the Max help files.
So if we go to this midiout device and hover on the left hand side,
we'll get a triangle.
And if I click on it, we have all these options, particularly Help
and Reference.
And both of these will give you great information about the device
and some ideas on other helpful devices.
It will give me an example patch, which is
great to see how it works, and also, on the right side
here, a bunch of excellent other help files and ideas on other really
useful devices related to MIDI.
And I see here this one called midiparse,
and it says, interpret raw MIDI data.
And so this process of, like, opening up help files of similar patches and kind
of searching around and finding the right device-- it's just
part of the process.
And what I'm trying to do at this point is interpret this raw MIDI data
and pull out the note information.
And there's this option here for midiparse, which I'll double click on,
which opens up another patch.
But if I look at this one, we see, oh, this is interesting.
If it gets a note on message, then we'll see midiparse here.
And we have note on, note off.
It looks like this is really what I want.
So I'm just going to try to play with it a bit and see how it works.
I'll close up these patches.
I'll hit the N key to create a new object,
and I'll type in midiparse, which has a ton of different outputs.
I'll place this right here, go from midiin down to the midiparse object
to send MIDI to there, and I'll start hovering over these output objects.
And this first one, when I hover over it,
says midiparse note on and note off.
It's a list of pitch and velocity.
Interesting.
Let's try to see what that actually sends.
So I'll add a new Print device.
Hit N, type Print, and I'll connect the output of the note
on and note off output over to the input port of Print.
Now, as we do this, I'll now want to identify which print device.
I could just hit a key on my keyboard, and I got more information here
in the Max console.
I need to know which Print device is printing over here.
So I'll double click on any Print device, go to the right,
hit space, and add in an indicator.
In this, I'll just type in raw MIDI.
In this one, I'll double click, and I'll type in another indicator, which
is going to be midiparse note out.
And now I'll hit a key and look at the Max console.
So I see that as I hit this key and hold the note down,
I see raw MIDI, which is this Print device, and it's getting 144, 60, 120.
And then the midiparse note out, which is right here, is just 60 and 120.
So I have a single list right here.
Now notice the difference here.
So this raw MIDI output sent a variety of individual messages--
number 60, and number 120, this number 144.
And then we have the midiparse note out as a single message
that includes two separate numbers.
We call this a list.
A list is a collection of messages.
You can kind of think of it like an English sentence.
A message is a word, and a list is a sentence.
And this one message contains these two separate messages.
One of them is going to be velocity, and one of them is going to be note.
Let's figure out which one.
So if I release my key, we see that the first one is a 60-- the same number.
That must be the note number.
And the second one is velocity, saying it's a note off.
So that first key-- that midiparse note out--
gave me a note of 60, and a velocity of 120.
I hit the key pretty hard.
And then when I release the key, I have a note of 60 and a velocity of 0.
That's a note off.
So I think I'm getting closer to having just the information I want.
All I really care about is that 60 because that is the note name.
That's what we're looking for-- a single message that is the note number.
My hand just hit a knob on my controller, and it sent this data here.
And you'll notice it's only coming out of the print raw MIDI Print
device, because it's a control change.
If I move this more, we'll see that we get a whole bunch of data.
It's all 176, which is saying it's a controller number.
And we're getting 4 and 13, or 4 and up to 127.
The raw MIDI 176 must be saying that it's a controlling number.
The 4 must be which controller it is.
And the 126 or 127 is the value of it.
Now, I don't need to look at this raw MIDI data
anymore because I'm really only concerned with the note outs.
So I'll click on the raw MIDI, Print device, delete it.
And I can go to my Max console, click this x, and clear it out.
Because I know that if I hit a note, I now
have a really good indication of what it is.
Note 48, velocity 127.
Note 48, velocity 0.
So I'll put this out to the side here, which is what I often do.
I'm often adding objects and then putting the print objects over
to the side to kind of get out of the way of everything I'm doing.
Now, the next thing I want to do is divide this out
so I only have one of these two messages.
And we're often doing this.
We have a list that is two numbers, and I
need to break it up into two separate messages.
And that's what the unpack device is for.
So I'll hit N and then Unpack.
The idea is we can pack messages into a list,
or we can unpack a list into individual messages.
And this is saying break a list into individual messages.
Perfect.
And I'll hit Enter.
Notice that this has a single input port--
the list to be unpacked.
And it has two output ports-- element one of list, and element two of list.
I'll click and drag from the output port of the midiparse device
and drag it to the input port of the unpack device.
Put that in place.
And then we can make another Print object.
So I'll New, Print.
And I'm going to call this UNPACKPORT1.
And I'll make another one that is UNPACKPORT2.
And I just option drag to make a copy of it.
So we have port 2, port 1.
So now, I'll try hitting a note.
And what do we have?
We have midiparse note out, a list--
that's 60 and 120.
UNPACKPORT2 is 120, and UNPACKPORT1 is 60.
So this is a really important point to make.
Messages happen in a certain order.
Though it looks like everything's happening all at once,
things are actually happening in an order.
If I clear out the Max console and I hold a key down, first, what happens
is the midiparse note out--
this object here.
And that's happening first because the MIDI comes in, goes to midiparse,
comes out of midiparse, then goes to here, and then it goes down to unpack,
and then it gets divided into these two destinations.
Now, note that the messages are sent on the right port
and then to the left port.
So we have UNPACKPORT2 as the velocity and UNPACKPORT1 as the note.
Messages coming out of objects will always happen from the right-most port
and then move to the left.
It feels a little odd at first.
But as you start developing the programs here in Max,
you'll find it makes total sense.
And it really is a logical way for this to function.
If I release my key, we'll get a note off event.
Again, we're going to see midi note out--
this device here-- sending a message to the Max console.
And then we have UNPACKPORT2 right here, and then UNPACKPORT1 right here.
Now, I'm not really concerned with UNPACKPORT2.
I can just delete that device.
I'm not really concerned with midiparse note out anymore.
I can delete that.
Really, all I care about is this note message.
So I'll make a new device.
Now, if we come up here, we see the Max for Live objects.
I can click there.
And we have a number of different interface objects.
And the one I'm really looking at right here is live.numbox.
I can click on that and I get a live number box.
I can click and drag that right here.
I can drag from the output port 1 of the unpack
object down to the input port of the live numbox.
Now, if I play a key on the keyboard, I'll see a 60.
If I play another key, I'll see a 63.
So what's happening is what was going here--
over to the Max console, that end number--
is now going to this number box.
I can click on unpack port and get rid of it.
And we really have the bulk of our MIDI note viewer object.
Now that we're seeing the data that we need to see,
I'd like to clean this up a little bit and give myself some comments.
Comments are created just like creating objects, but we don't hit the N key.
We hit the C for comment.
And I can say something like this.
If you have a chance to clean up your patch and to give details,
that's awesome.
Over here-- and I'll put another comment.
With my patch well-commented, I can save it--
command S. And then I can give it a good name.
I'll call this note display 2 because I've been working on a bunch of these.
And I can close up the Max interface.
And we'll see that our complete patch is shown here inside of Live.
And I can hit a key on my keyboard.
And it'll show the latest note right there.
So now we see how we can develop an object in Max
and how we can get a simple note display over in Live.
But there are some problems.
First off, this is an ugly interface.
The end user in Live doesn't need to see all this information.
All they really need is this number box right here.
And it's not showing me the MIDI note name.
I'd rather say C, C sharp, et cetera.
To fix all these little issues, I'll go and edit the patch a little more.
Click on this button right here to edit it.
Open the Max editor.
Now, most of the issues I had were relating to this Live number box
right here.
And what I need to do is change a number of this object's attributes.
Attributes are aspects of an object that control how it looks and how it acts.
If I click on this and then I click this I for inspector here,
we'll see a list of all the object's attributes.
We can show tabs to show specific portions of the attributes.
And I can also hide and show portions of the interface here.
Now, I'll go to all and all scroll down all the way to the unit style.
If I hover over the I there, there will be
even information about the unit style.
It's saying that parameters have a number of built-in display
styles for their data.
Choose between them in the drop-down menu.
And the drop-down menu here has all sorts of different ways
that that number can be displayed.
The one we're going to want is MIDI.
So this way, it says D sharp 4.
And if I click different keys on my keyboard,
we are seeing that it's showing MIDI note numbers really nicely right there.
The next thing is to make a custom interface
for this device that only includes the display, the note
number, and the comment for it.
To do this, I'll click on my Live number box and go back to the inspector.
And then we'll find the attribute for presentation, Include in Presentation.
And I'll checkbox that.
Now, once I do that, I'll see there's a kind of reddish pinkish box around it.
And that's saying this object, if I switch to the Presentation Mode,
will be viewed there.
And we can switch to the Presentation Mode with this button right down here--
Presentation Mode.
If I click on it, everything else will disappear, and only
that F3 is available.
If I click on this again, it will go back
to the Patching Mode, where we can edit.
So the Presentation Mode, when I'm here--
and this says, unlocked presentation-- the Presentation Mode is the view that
will be available in Live.
And then the Patching View is how we can come in here and edit our patch.
Now, I also want this comment to be in the Presentation Mode,
so I'll click on it.
And I'll find Include in Presentation over here
in the attributes, which is right here.
Now, the honest truth is this is such a common thing to do.
You can Control click or right click, and there
will be an option for Add to Presentation, which is simply
checking that box but allowing you to do it without opening the info pane.
And I can actually move these objects in the Presentation Mode up here.
I can even change their size.
And if I switch back to the Patching View,
we'll see it moves over to this location.
So objects have their own location in Presentation and Patching.
The last thing I'll have to do is tell Live that when I'm opening this patch,
I'd like to open it in the Presentation Mode.
And there's an option.
If you click on the background here, while in the Patcher,
you'll see that this little P shows up right there.
If I click on an object, that P disappears.
But if I click in the background, I'll see it there
while I'm in the inspector.
That P is going to give me the Patcher inspector.
So it'll give me the info about the Patcher itself--
kind of the background.
And if I scroll down, I'll find an attribute for Open in Presentation.
And there it is.
Under view, you have an option for Open in Presentation.
And I can make that checkbox.
Now, once I do that, I can switch to the Presentation Mode and hit Save.
And I'll do a Save As.
And I'll save this as Note Display 3 for myself.
And as soon as I did that, because that was checked,
look at what I see over in Live.
I'll just quit Max here.
And I have a really nice interface that shows me
exactly what the last note played is.