WEBVTT
Kind: captions
Language: en-US

00:00:00.000 --> 00:00:04.371
For the last few weeks, I've been working
on making my 3D printer do this.

00:00:16.516 --> 00:00:20.420
Not only that, but I've also developed
a method to transcribe music

00:00:20.420 --> 00:00:25.125
as complex as this into G-code,
which is specific to your 3D printer.

00:00:25.458 --> 00:00:28.461
Today I introduce to you 3MeloD.

00:00:43.243 --> 00:00:45.445
we all know and love 3D printers.

00:00:45.445 --> 00:00:49.049
They turn long strings of plastic
into things like prototypes,

00:00:49.482 --> 00:00:52.052
toy rockets, even real rockets.

00:00:52.052 --> 00:00:54.921
But sometimes amazing technology is used
in ways

00:00:54.921 --> 00:00:57.924
that are unforeseen.

00:00:58.091 --> 00:01:00.260
Unanticipated, if you will.

00:01:00.260 --> 00:01:00.693
So there

00:01:00.693 --> 00:01:05.298
I was, studying for a big upcoming exam
when I got this itch to misuse technology.

00:01:05.565 --> 00:01:10.136
I was sitting there watching my printer
do its thing, and I noticed that sometimes

00:01:10.136 --> 00:01:14.374
when it moved in a certain way, it sounded
as if it were playing certain notes.

00:01:16.943 --> 00:01:18.078
In that moment, I

00:01:18.078 --> 00:01:21.781
decided that my printer
was no longer a tool, but an instrument.

00:01:22.048 --> 00:01:25.251
by the way, if you're like me
and you use your printer for anything

00:01:25.251 --> 00:01:28.621
but 3D printing,
check out this video's sponsor Pcbway.

00:01:28.755 --> 00:01:31.891
Their 3D manufacturing services
can provide you with any part

00:01:31.891 --> 00:01:34.894
and almost any type of material,
while you and your printer

00:01:34.894 --> 00:01:36.429
tend to more important things.

00:01:36.429 --> 00:01:39.432
In my previous video on Linear rails,
I used Pcbway

00:01:39.499 --> 00:01:42.902
3D printing and aluminum
CNC machining services.

00:01:43.136 --> 00:01:46.439
All the parts I received
were fantastic and exactly to spec.

00:01:46.439 --> 00:01:50.376
So if you need something
like aluminum parts or exotic resin parts,

00:01:50.577 --> 00:01:51.911
check out pcbway.

00:01:51.911 --> 00:01:54.347
Thanks again to Pcbway
for sponsoring this video.

00:01:54.347 --> 00:01:57.083
And now let's
get back to talking about music.

00:01:57.083 --> 00:02:00.487
So before we even consider the possibility
of our 3D printer

00:02:00.487 --> 00:02:04.657
being able to make music, we kind of have
to break down what is music?

00:02:14.434 --> 00:02:15.735
Music is a collection of

00:02:15.735 --> 00:02:18.738
noises played in some sort of pattern.

00:02:18.738 --> 00:02:20.874
These noises we call notes.

00:02:20.874 --> 00:02:23.476
Notes define the pitch of our sound.

00:02:23.476 --> 00:02:27.213
how high or low they sound The pattern
that assembles our noises

00:02:27.213 --> 00:02:31.551
into beautiful
musical compositions is called rhythm.

00:02:31.651 --> 00:02:32.418
So I guess

00:02:32.418 --> 00:02:36.222
the first logical step is to figure out
how to play notes on the printer.

00:02:36.356 --> 00:02:39.425
From what I'd already observed,
I realized that when the printer moved

00:02:39.425 --> 00:02:42.428
at certain speeds,
I would hear certain notes.

00:02:42.562 --> 00:02:46.099
So what I did was sit next to my printer
with the guitar, and I would play certain

00:02:46.099 --> 00:02:49.102
notes and tweak the speeds
that the printer would move at

00:02:49.402 --> 00:02:52.405
until I found two sounds that matched.

00:02:54.507 --> 00:02:55.742
Changing the speed of the printer.

00:02:55.742 --> 00:02:57.877
Is kind of
like tuning a string on a guitar.

00:02:57.877 --> 00:03:00.280
Lower speed,

00:03:01.347 --> 00:03:02.482
higher speed

00:03:02.482 --> 00:03:04.717
Once I found the speed
that played a certain note,

00:03:04.717 --> 00:03:06.853
I would write it down
and move to the next one.

00:03:06.853 --> 00:03:11.024
After defining a bunch of notes necessary
for one song, I did a whole bunch

00:03:11.024 --> 00:03:14.627
of monotonous calculations
and ended up with this.

00:03:22.635 --> 00:03:23.803
Now, don't get me wrong.

00:03:23.803 --> 00:03:30.210
This felt really good, but I just
spent hours doing tons of monotonous math

00:03:30.743 --> 00:03:33.780
and I'd only gotten
through a few measures of a song.

00:03:33.780 --> 00:03:35.648
I knew there had to be a better way.

00:03:35.648 --> 00:03:39.452
So again, I ask myself,
how do we play a note on the printer?

00:03:39.552 --> 00:03:44.090
I know that when we move a certain speed
on our axes, that a certain note is heard.

00:03:44.090 --> 00:03:47.093
But what's going on behind the scenes?

00:03:47.093 --> 00:03:50.029
Why is that certain speed playing
a certain note?

00:03:50.029 --> 00:03:53.299
Well, a note's
pitch is defined by its frequency.

00:03:53.600 --> 00:03:55.201
The frequency is the amount of times

00:03:55.201 --> 00:03:58.204
that something occurs
in a given amount of time.

00:03:58.304 --> 00:04:01.341
For example, I brush my teeth twice a day.

00:04:02.575 --> 00:04:05.578
Abstractly put, an event occurs

00:04:05.945 --> 00:04:09.349
two times in the time interval of one day.

00:04:09.616 --> 00:04:12.418
Another example would be the tachometer
in a car.

00:04:12.418 --> 00:04:15.922
The tachometer in your car tells you
how many revolutions per minute

00:04:15.989 --> 00:04:18.358
that your engine shaft
is rotating in your car.

00:04:18.358 --> 00:04:21.361
When we talk about sound, though,
we use a unit called Hertz.

00:04:21.694 --> 00:04:24.697
Also known as one over
second or per second.

00:04:24.697 --> 00:04:29.135
With sound, the thing occurring per second
is the number of sound waves.

00:04:30.503 --> 00:04:32.839
What these really are
are compression waves.

00:04:32.839 --> 00:04:34.540
And an easy way to think about this,

00:04:34.540 --> 00:04:38.144
to get a better understanding
is to think of a speaker.

00:04:38.478 --> 00:04:41.214
Basically,
when that woofer moves back and forth.

00:04:41.214 --> 00:04:43.583
We get these compression waves.

00:04:43.583 --> 00:04:48.288
Or basically you can see this area
of high density of particles in the air.

00:04:48.521 --> 00:04:51.124
And then in between
you have a lower density.

00:04:51.124 --> 00:04:52.425
and basically these pressure waves

00:04:52.425 --> 00:04:56.262
are what we're representing
when we show a sound wave.

00:04:56.262 --> 00:05:00.900
can see that the peaks correlate to the
densest areas of the compression waves.

00:05:01.034 --> 00:05:03.936
so. We should just be able to do something
a bunch of times

00:05:03.936 --> 00:05:05.471
per second on our printer.

00:05:05.471 --> 00:05:08.074
And it will make these compression
waves that, that frequency.

00:05:08.074 --> 00:05:09.676
Easy enough. Let's give it a try.

00:05:14.314 --> 00:05:14.781
Okay.

00:05:14.781 --> 00:05:17.850
Well, we can't actually just do something
a bunch of times per second.

00:05:18.017 --> 00:05:21.020
The actual solution
lies here in the stepper motors.

00:05:21.020 --> 00:05:23.623
Our stepper motors can rotate quite fast.

00:05:23.623 --> 00:05:27.360
Not hundreds of times per second, fast,
but quite fast.

00:05:27.527 --> 00:05:30.530
But they can do something else
very quickly.

00:05:30.596 --> 00:05:31.431
Step.

00:05:31.431 --> 00:05:35.234
If you're not familiar, stepper motors
turn by turning on and off

00:05:35.234 --> 00:05:39.205
magnetic coils,
which slowly step these two offset gears.

00:05:39.672 --> 00:05:42.508
One of these movements is called a step.

00:05:42.508 --> 00:05:45.244
So now we just need to figure out
how to make our stepper

00:05:45.244 --> 00:05:48.247
motors go a defined amount of steps
per second.

00:05:48.448 --> 00:05:52.318
Now, the number we're going to shoot
for first is 440 steps per second.

00:05:52.618 --> 00:05:55.621
Don't worry about why for now,
but we're going for 440.

00:05:55.621 --> 00:05:57.256
So let's get started.

00:05:57.256 --> 00:05:58.991
What do we already know?

00:05:58.991 --> 00:06:01.060
Well, we just covered that stepper motor.

00:06:01.060 --> 00:06:04.630
Shafts turn a certain amount of degrees
per step.

00:06:05.231 --> 00:06:08.501
The two most common degrees per
step that we see in 3D

00:06:08.501 --> 00:06:12.305
printing is 3.6 degrees and 1.8 degrees.

00:06:13.106 --> 00:06:16.943
Also,
we know because circles that a circle

00:06:17.477 --> 00:06:20.480
is comprised of 360 total degrees.

00:06:20.613 --> 00:06:25.251
360 degrees divided by 3.6 degrees.

00:06:25.618 --> 00:06:29.589
First up is going to give us 100 steps.

00:06:29.789 --> 00:06:32.792
And you can see that for the 1.8
degree stepper motor

00:06:33.393 --> 00:06:35.728
that would give us 200 steps.

00:06:35.728 --> 00:06:39.232
And that is the amount of steps
it takes for one full revolution.

00:06:39.232 --> 00:06:43.369
so with 3.6 degrees per step
being the more common configuration in 3D

00:06:43.369 --> 00:06:45.471
printing, that is the configuration I'm

00:06:45.471 --> 00:06:47.640
going to assume
for the remainder of the video.

00:06:47.640 --> 00:06:50.610
So we now know that one revolution

00:06:51.277 --> 00:06:53.613
is equal to 100 steps.

00:06:53.613 --> 00:06:56.048
So if we want to go 440

00:06:56.048 --> 00:07:00.219
steps per second,
and we know it's 100 steps per revolution,

00:07:00.353 --> 00:07:05.358
then we can quickly find that 440
divided by 100 steps

00:07:05.358 --> 00:07:10.997
per revolution is going to give us
4.4 revolutions per second.

00:07:11.063 --> 00:07:14.767
So we now know that our stepper motor
needs to rotate 4.4 times per

00:07:14.767 --> 00:07:18.137
second to give us 440 steps per second.

00:07:18.304 --> 00:07:21.474
Now that's great now, but there's no
G-code command that tells our printer

00:07:21.474 --> 00:07:25.278
to rotate one of its axes
4.4 times per second.

00:07:25.378 --> 00:07:30.616
Instead, our G-code commands are moved
from this point to this point.

00:07:30.850 --> 00:07:32.185
At this speed.

00:07:32.185 --> 00:07:35.254
So instead of defining things
in revolutions per second,

00:07:35.321 --> 00:07:39.358
we need to figure out how fast it has
to travel in a linear distance per second.

00:07:39.459 --> 00:07:41.527
Luckily, this is fairly straightforward.

00:07:41.527 --> 00:07:43.362
Now if you've worked with Klipper before,

00:07:43.362 --> 00:07:46.399
then you should be familiar with distance
traveled per revolution.

00:07:47.033 --> 00:07:49.702
This is something that we have
in our configuration file

00:07:49.702 --> 00:07:52.905
to tell Klipper how far our axes travel.

00:07:53.272 --> 00:07:55.641
For one full revolution
of our stepper motor.

00:07:55.641 --> 00:07:56.742
For instance.

00:07:56.742 --> 00:08:01.013
My x axis travels at 40mm per revolution.

00:08:01.280 --> 00:08:05.418
My y axis travels at 32mm per revolution.

00:08:05.585 --> 00:08:09.422
And my z axis travels at eight millimeters
per revolution.

00:08:09.922 --> 00:08:11.524
The reason that these values are different

00:08:11.524 --> 00:08:13.626
isn't
because the stepper motors are different.

00:08:13.626 --> 00:08:15.862
They're actually the same. In my case.

00:08:15.862 --> 00:08:20.733
The reasoning is that the gear pulleys
that drive our axes are not the same.

00:08:21.467 --> 00:08:25.371
For instance,
my x axis one is going to be larger

00:08:26.038 --> 00:08:28.307
and my y axis one is going to be smaller.

00:08:29.275 --> 00:08:32.178
And this
is because the x axis is a lot lighter.

00:08:32.178 --> 00:08:35.882
So we can get we can take advantage
of that larger radii of the gear.

00:08:36.749 --> 00:08:39.785
So if you think about the circumference
of our circle,

00:08:40.820 --> 00:08:44.123
that red line is going to be a lot
longer than that red line.

00:08:44.624 --> 00:08:48.027
So now we know that
when my x axis revolves one time

00:08:48.494 --> 00:08:52.098
that our x axis
is going to travel 40mm linearly.

00:08:52.331 --> 00:08:56.202
So if we now go back to that 4.4
revolutions per second that we want to do.

00:08:56.769 --> 00:09:01.440
And we know that our axis moves 40mm
per revolution.

00:09:01.674 --> 00:09:03.843
We now can multiply these together.

00:09:03.843 --> 00:09:06.479
And we find that we need to move at

00:09:06.479 --> 00:09:10.850
176mm per second
if you've kept up this far,

00:09:10.850 --> 00:09:15.354
then you should be able to see
now that 440 steps per second

00:09:15.488 --> 00:09:19.926
That's going to be equivalent
to 176mm per second.

00:09:19.926 --> 00:09:21.294
And that's for the x axis.

00:09:21.294 --> 00:09:24.297
So if I want to play a note at 440Hz,

00:09:24.797 --> 00:09:28.601
then I know that I need to move
176mm per second.

00:09:28.768 --> 00:09:31.771
But again, I don't just tell my printer
how fast to move.

00:09:32.104 --> 00:09:34.607
I also have to tell it how far to move.

00:09:34.607 --> 00:09:39.245
So I'm going to assume that we want
to play our note for a time of one second.

00:09:40.212 --> 00:09:43.215
So if
we multiply the time to our velocity,

00:09:43.249 --> 00:09:47.520
then we know that we need to move 176mm

00:09:48.087 --> 00:09:52.391
at 176mm per second.

00:09:52.491 --> 00:09:53.626
The last thing we need to do

00:09:53.626 --> 00:09:57.697
is convert our speed to the feed
rate of a G-code command.

00:09:58.030 --> 00:09:58.898
For some reason,

00:09:58.898 --> 00:10:02.535
G-code is in millimeters
per minute, not in millimeters per second.

00:10:02.935 --> 00:10:07.506
So we just need to multiply our number
176 times 60.

00:10:07.506 --> 00:10:11.911
So, using this information,
if we assume that our printer

00:10:12.111 --> 00:10:15.114
is going to start at x equals zero.

00:10:15.181 --> 00:10:18.250
So in about the home position
This should be our G-code.

00:10:18.985 --> 00:10:21.854
So this just tells our printer to move
from its current position.

00:10:21.854 --> 00:10:25.858
X equals zero to the point 176

00:10:26.359 --> 00:10:29.862
at a feed rate of 10,560mm per minute.

00:10:29.996 --> 00:10:31.030
So let's quickly check

00:10:31.030 --> 00:10:35.034
and see if an A4 on the guitar
sounds like an A4 on the printer.

00:10:35.401 --> 00:10:36.535
It should sound like this.

00:10:42.742 --> 00:10:43.175
Okay.

00:10:43.175 --> 00:10:43.776
That's cool.

00:10:43.776 --> 00:10:48.147
We can play a single note, but music is
made up of lots of different notes.

00:10:48.481 --> 00:10:50.850
How are we going
to get all those other notes?

00:10:50.850 --> 00:10:53.853
Well, we just need to know the frequency
of all the other notes.

00:10:53.886 --> 00:10:56.255
If we know the frequency of the note,
we can find out

00:10:56.255 --> 00:10:59.225
the travel speed that results
and the creation of that note.

00:10:59.258 --> 00:11:02.094
Now, at first glance,
that seems like a ton of work,

00:11:02.094 --> 00:11:04.930
This is where that 440Hz comes in.

00:11:04.930 --> 00:11:07.900
When we play a note at 440Hz,

00:11:07.900 --> 00:11:10.903
that's referred to as A4.

00:11:11.904 --> 00:11:12.505
and music.

00:11:12.505 --> 00:11:14.173
Standard tuning system.

00:11:14.173 --> 00:11:17.176
A4 is referred to as the reference
frequency.

00:11:17.309 --> 00:11:20.312
It's called the reference frequency
because all of the other notes

00:11:20.312 --> 00:11:23.616
we can play
are defined relative to that A4.

00:11:23.616 --> 00:11:26.552
Note.
But how are they related to each other?

00:11:26.552 --> 00:11:29.255
Let's figure that out. This is A5.

00:11:30.790 --> 00:11:31.924
It's the same exact

00:11:31.924 --> 00:11:34.927
note played an octave higher.

00:11:35.761 --> 00:11:37.129
You can probably hear they sound like

00:11:37.129 --> 00:11:40.132
the same note as opposed to

00:11:40.499 --> 00:11:41.233
any other note.

00:11:41.233 --> 00:11:44.336
Now, when I say something is an octave
higher or an octave lower,

00:11:44.737 --> 00:11:47.473
this means that the frequency
that the octave higher

00:11:47.473 --> 00:11:50.476
notice played up is twice
the frequency of a reference note.

00:11:50.743 --> 00:11:53.746
So A4 is 440Hz

00:11:54.046 --> 00:11:57.049
and A5 is 880Hz.

00:11:57.216 --> 00:12:01.721
On the other hand, if we go down
an octave, we divide our frequency by two.

00:12:01.954 --> 00:12:04.890
So if we have A4 at 440Hz,

00:12:04.890 --> 00:12:07.893
then we have A3 at 220Hz.

00:12:09.829 --> 00:12:11.297
This octave relationship

00:12:11.297 --> 00:12:14.967
is kind of a natural miracle of music,
so we just have to take it as fact.

00:12:15.234 --> 00:12:18.637
So this is the equation
that defines our frequencies

00:12:18.938 --> 00:12:22.174
that are an octave up or an octave below
or however many octaves

00:12:22.174 --> 00:12:25.978
in whatever direction you want to go
So we assume that our reference

00:12:25.978 --> 00:12:29.148
frequency is equal to 440Hz.

00:12:29.348 --> 00:12:31.717
Which is again a four.

00:12:31.717 --> 00:12:36.355
So if we want to go an octave up,
then I will say that n is equal to one.

00:12:36.856 --> 00:12:40.826
If we plug these into our equation
we get that 440Hz.

00:12:41.026 --> 00:12:45.798
Times
two raised to the one is equal to 880Hz.

00:12:46.098 --> 00:12:51.437
And that is indeed the frequency
which is for the notes a five.

00:12:51.604 --> 00:12:55.975
If we want to go down an octave, then
we know that n is equal to negative one.

00:12:56.108 --> 00:13:01.180
If n is equal to negative one and we again
plug that into our octave equation,

00:13:01.814 --> 00:13:05.584
we get 440Hz times
two raised to the negative one power,

00:13:06.118 --> 00:13:09.755
which does indeed give us 220Hz.

00:13:10.289 --> 00:13:13.626
The frequency of the note, called A3.

00:13:13.759 --> 00:13:14.794
So that's great.

00:13:14.794 --> 00:13:18.063
Now, now we know how to find
the frequencies for all of the notes.

00:13:18.330 --> 00:13:21.500
But how do we find the frequency
for the notes in between them?

00:13:21.967 --> 00:13:27.573
If we start at A4 and we play up
until the next A5, we count.

00:13:32.244 --> 00:13:34.346
12 notes.

00:13:34.346 --> 00:13:37.349
So there are 11 notes
in between the two A's,

00:13:38.517 --> 00:13:41.520
and we play 12
separate notes to get up to the.

00:13:43.722 --> 00:13:45.758
Now, your first instinct
might be to divide up

00:13:45.758 --> 00:13:49.428
all of the frequencies
between 440Hz and 880Hz.

00:13:49.528 --> 00:13:51.430
So let's
go ahead and do that on the printer

00:13:51.430 --> 00:13:54.433
and see what that sounds like.

00:13:58.370 --> 00:14:01.407
As your ears probably told you,
that didn't sound quite right.

00:14:01.674 --> 00:14:04.677
This is what it should sound like.

00:14:06.078 --> 00:14:09.081
So the reason that doesn't sound
quite right is because remember,

00:14:09.248 --> 00:14:12.718
with our octave notes,
we defined a base two relationship.

00:14:13.285 --> 00:14:16.288
Basically, if we look at this on a graph,

00:14:16.889 --> 00:14:19.225
we see that this is 220,

00:14:19.225 --> 00:14:22.494
440 660 and 880.

00:14:23.395 --> 00:14:26.765
We know that our note started here,
and then it went here.

00:14:27.233 --> 00:14:29.168
And then it was all the way up here.

00:14:29.168 --> 00:14:31.637
So we can see that this

00:14:32.738 --> 00:14:35.474
is something that
resembles an exponential relationship.

00:14:35.474 --> 00:14:39.311
But what we've done is instead of
interpolating at this exponential curve,

00:14:39.545 --> 00:14:42.548
We have instead done
a linear interpolation,

00:14:42.748 --> 00:14:45.618
which if you extrapolate past

00:14:45.618 --> 00:14:48.954
any of these notes,
is going to be very wrong.

00:14:49.221 --> 00:14:53.058
And you can see that
depending on where you extrapolate from.

00:14:53.559 --> 00:14:56.595
You're going to get very different notes.

00:14:57.129 --> 00:15:00.232
so instead of interpolating
and extrapolating linearly,

00:15:00.532 --> 00:15:03.535
we need to use this base two relationship.

00:15:03.702 --> 00:15:07.473
So let's again
take a look at our octave equation.

00:15:07.606 --> 00:15:10.609
We again have our frequency

00:15:10.709 --> 00:15:13.178
is equal to our reference frequency

00:15:13.178 --> 00:15:16.015
times two raised to the n.

00:15:16.015 --> 00:15:20.152
Now this is where
we're going to divide up our frequencies

00:15:20.152 --> 00:15:24.690
into 12 separate notes
to get from our A4 to our A5.

00:15:24.823 --> 00:15:27.726
Instead of N just being one.

00:15:27.726 --> 00:15:32.131
Why don't we make it fractional
so that we can basically divide

00:15:32.765 --> 00:15:35.768
that octave up into 12 separate segments?

00:15:35.968 --> 00:15:37.069
So what we're going to do

00:15:38.237 --> 00:15:39.905
is divide in by 12.

00:15:39.905 --> 00:15:45.811
that's our f ref is equal to A4,
then A5. Is the frequency

00:15:45.811 --> 00:15:48.814
that we'll get when we input n equals 12.

00:15:48.914 --> 00:15:50.749
So if we put in n equals 12

00:15:50.749 --> 00:15:54.620
we get two raised to the 12 over 12
which is two raised to the one.

00:15:54.787 --> 00:15:57.790
Which is just going to multiply
our frequency by two

00:15:58.090 --> 00:16:00.926
and still retain that octave relationship.

00:16:00.926 --> 00:16:03.062
And it'll work with -12 as well.

00:16:03.062 --> 00:16:06.899
But now we've unlocked the ability
to get all of our other notes.

00:16:07.199 --> 00:16:10.202
So let's put in n equals two

00:16:10.469 --> 00:16:13.072
which should give us b4

00:16:13.072 --> 00:16:17.142
which last time we said was about 520Hz.

00:16:17.376 --> 00:16:20.346
Based on the linear interpolation
which we know is wrong.

00:16:20.346 --> 00:16:24.416
So if we do any equals 12,
then we get two raised to the one over

00:16:24.416 --> 00:16:27.519
six times 440 is equal to.

00:16:27.853 --> 00:16:31.156
approximately 494Hz.

00:16:31.457 --> 00:16:35.194
So it looks like our original
guess was off by almost 30Hz,

00:16:35.194 --> 00:16:38.197
which is in this range non-negligible.

00:16:38.397 --> 00:16:41.800
So let's go ahead and use this
relationship to solve for n equals

00:16:41.800 --> 00:16:45.404
one through 12, so that we can fill out
all the rest of the notes that we need.

00:16:45.771 --> 00:16:48.107
let's go ahead and see how
that sounds on the printer.

00:16:52.578 --> 00:16:53.712
That sounds great.

00:16:53.712 --> 00:16:57.616
So now we should be able to extrapolate
from this equation to all the other notes

00:16:57.616 --> 00:17:01.120
and theoretically play any note
we want on our printer.

00:17:01.353 --> 00:17:04.390
But remember music isn't just notes,
but also

00:17:04.623 --> 00:17:09.161
rhythm. But.

00:17:15.467 --> 00:17:17.903
So let's take a quick look at rhythms.

00:17:17.903 --> 00:17:23.442
Just as we had a 440Hz reference note,
we also have references for rhythms.

00:17:23.709 --> 00:17:27.546
typically there are two numbers out
in front of the beginning of our song.

00:17:28.113 --> 00:17:31.116
And we have this other number.

00:17:31.216 --> 00:17:34.820
So this top number basically tells us
that we have four quarter notes

00:17:34.820 --> 00:17:37.823
per measure,
which isn't really important for us.

00:17:38.057 --> 00:17:40.859
But this bottom note
is telling us that our quarter note

00:17:40.859 --> 00:17:43.962
is what is played in a total of one beat.

00:17:44.463 --> 00:17:47.433
So if you feel music
and you feel that beat,

00:17:47.433 --> 00:17:49.301
each one of those
is going to be a quarter note.

00:17:50.502 --> 00:17:53.439
And we know that
there will be four of those per measure,

00:17:53.439 --> 00:17:56.775
We then have this third number up top,
which tells us that

00:17:57.342 --> 00:18:00.679
a quarter note is played
60 times per minute.

00:18:01.280 --> 00:18:04.383
So I conveniently chose this
so that we would have a quarter

00:18:04.383 --> 00:18:07.386
note per second.

00:18:07.419 --> 00:18:10.422
So if we had music
made of just quarter notes,

00:18:10.422 --> 00:18:14.793
we would have something like this
and that first measure would take

00:18:14.793 --> 00:18:18.630
four seconds to play because we play 60
quarter notes per minute.

00:18:18.997 --> 00:18:21.900
So it would take four seconds
to play four quarter notes.

00:18:21.900 --> 00:18:24.770
A quarter note looks something like that.

00:18:24.770 --> 00:18:27.139
Next we have something
called an eighth note.

00:18:27.139 --> 00:18:29.575
And I'm not going to go through
every single rhythm possible.

00:18:29.575 --> 00:18:31.810
That would take way too long.
And it doesn't matter.

00:18:31.810 --> 00:18:34.680
I'm just going through a few of
the basic ones to have an understanding.

00:18:34.680 --> 00:18:37.649
Basically, an eighth note
is half the value of a quarter note.

00:18:37.683 --> 00:18:41.653
So a single quarter note is equal to
to eighth notes,

00:18:41.954 --> 00:18:46.258
Next we have
and maybe you guessed it a 16th note.

00:18:46.558 --> 00:18:50.662
And you may have guessed it again,
but a quarter note is equal

00:18:50.662 --> 00:18:53.866
to four 16th notes, eighth note

00:18:54.366 --> 00:18:57.436
is equal to two 16th notes.

00:18:58.137 --> 00:19:01.573
So in this way, if we're at 60 beats

00:19:01.573 --> 00:19:05.077
per minute we know that a quarter note
is equal to one second.

00:19:05.711 --> 00:19:08.714
An eighth note is equal to half a second,

00:19:09.081 --> 00:19:13.519
and a 16th note is equal to 0.25 seconds.

00:19:14.119 --> 00:19:18.857
So real quickly let's figure out
how we would translate this into G code.

00:19:19.057 --> 00:19:22.060
So remember that to play an A4,
we need to move

00:19:22.060 --> 00:19:25.464
at 176mm per second,

00:19:26.398 --> 00:19:30.502
which we know if
we're at 60 beats per minute

00:19:31.737 --> 00:19:34.506
because we have 60 quarter notes
per minute,

00:19:34.506 --> 00:19:38.944
we know that we would need to move one
second to play a quarter note.

00:19:39.545 --> 00:19:42.814
So again,
that would give us 176 millimeter movement

00:19:43.982 --> 00:19:46.985
at 176mm per second.

00:19:48.053 --> 00:19:50.055
And that is equal to a quarter note.

00:19:50.055 --> 00:19:53.058
Now what if we want to do an eighth note.

00:19:53.091 --> 00:19:55.861
We still want to move

00:19:55.861 --> 00:19:59.765
at 176mm per second, because that defines

00:19:59.765 --> 00:20:02.768
the pitch of our note,
which we don't want to change.

00:20:03.035 --> 00:20:05.637
So instead, we know we need to move

00:20:05.637 --> 00:20:08.974
half the distance
because we want to take half the time.

00:20:09.875 --> 00:20:12.911
So instead we will move 88mm

00:20:13.312 --> 00:20:17.416
at 176mm per second to get an eighth note.

00:20:17.482 --> 00:20:19.952
And finally,
you may have guessed it already,

00:20:19.952 --> 00:20:22.955
but we would move 44mm

00:20:23.121 --> 00:20:27.693
at 176mm per second to get a 16th note.

00:20:28.327 --> 00:20:32.731
And basically that's how we're going to
create different rhythms with our G codes.

00:20:33.265 --> 00:20:36.602
So taking everything we've gone over
so far into consideration.

00:20:37.002 --> 00:20:38.637
Let's try and make our first sound.

00:20:38.637 --> 00:20:41.273
The one I chose to do is Sea Shanty 2.

00:20:41.273 --> 00:20:42.274
Let's see how it works.

00:20:54.486 --> 00:20:55.053
Nice.

00:20:55.053 --> 00:20:59.057
I can now sleep at night knowing that
I can play music on my 3D printer.

00:20:59.725 --> 00:21:02.728
See you.

00:21:05.163 --> 00:21:06.832
Sheesh.

00:21:06.832 --> 00:21:09.835
Long day...

00:21:11.503 --> 00:21:12.671
What if we want to play

00:21:12.671 --> 00:21:15.674
multiple notes at once?

00:21:16.408 --> 00:21:19.411
Currently, the printer can do this.

00:21:24.249 --> 00:21:27.252
But what if we want it to do this?

00:21:37.129 --> 00:21:37.929
So as I worked

00:21:37.929 --> 00:21:40.999
on the previous sections,
I started to realize that the method I was

00:21:40.999 --> 00:21:44.970
using was going to make playing
multiple notes at a time a problem.

00:21:45.304 --> 00:21:48.740
The issue is that we don't have a G-code
command that can tell

00:21:48.740 --> 00:21:51.743
our separate axes
to move at different speeds.

00:21:51.843 --> 00:21:53.245
And it's not like we can send

00:21:53.245 --> 00:21:57.349
a couple different G-code commands
and have them all be done at once, Now,

00:21:57.349 --> 00:22:01.119
this is because our printers can only read
one line of G code at a time.

00:22:01.453 --> 00:22:04.289
Basically,
we send them a bunch of G codes.

00:22:04.289 --> 00:22:08.493
They read one,
they execute it, and it disapears,

00:22:09.461 --> 00:22:11.330
and then we move on to the next line.

00:22:11.330 --> 00:22:13.231
And then we read that one
and it disappears

00:22:13.231 --> 00:22:14.800
and we move on to the next line.

00:22:14.800 --> 00:22:17.736
We can give it three different commands
that tell three different axes

00:22:17.736 --> 00:22:19.271
to move in three different ways.

00:22:19.271 --> 00:22:21.873
So we need to find a clever way
around that.

00:22:21.873 --> 00:22:24.509
And it's actually been in front of us
this whole time.

00:22:24.509 --> 00:22:28.780
When we issue a move command,
we are telling our printer

00:22:28.780 --> 00:22:32.184
to move at three different axes
all at the same time.

00:22:32.317 --> 00:22:35.320
But we're not defining a speed
for every single axis.

00:22:35.954 --> 00:22:40.692
So how is it that our axes are all moving
at different speeds?

00:22:40.726 --> 00:22:43.628
It And what is this
feed rate actually defining?

00:22:43.628 --> 00:22:46.898
It's pretty clear
when we only have an X or Y or Z,

00:22:47.099 --> 00:22:52.371
But when we have 2 or 3 axes
moving at once, what does that feed rate.

00:22:52.404 --> 00:22:53.772
Now defining.

00:22:53.772 --> 00:22:57.576
So to understand why that is,
we need to quickly talk about vectors.

00:22:57.843 --> 00:23:01.146
Vectors are wonderful quantities
that describe objects

00:23:01.146 --> 00:23:04.149
requiring
more than one number to be defined.

00:23:04.383 --> 00:23:07.386
Imagine you ask someone for directions
to the closest store

00:23:07.486 --> 00:23:10.489
and they tell you to go ten miles.

00:23:10.856 --> 00:23:11.890
Okay.

00:23:11.890 --> 00:23:13.558
What does that mean? Ten miles.

00:23:13.558 --> 00:23:15.260
Which direction?

00:23:15.260 --> 00:23:16.661
So that is a vector.

00:23:16.661 --> 00:23:19.664
A vector in this case has a magnitude

00:23:19.765 --> 00:23:22.934
that we will call the length
or the distance.

00:23:23.368 --> 00:23:28.540
And we've now requested that second
quantity which is equal to the direction.

00:23:29.174 --> 00:23:32.277
Say that the person tells us
that we need to travel

00:23:32.677 --> 00:23:35.313
in a east by northeast direction.

00:23:35.313 --> 00:23:37.883
if we were to draw this
on some sort of map.

00:23:37.883 --> 00:23:42.087
And we're starting down here, we might get
something that looks like this.

00:23:42.554 --> 00:23:45.056
So we know that we
have a distance of ten miles,

00:23:46.358 --> 00:23:47.659
and we have

00:23:47.659 --> 00:23:50.662
some direction relative to the direction
east.

00:23:50.962 --> 00:23:53.231
We now have a vector.

00:23:53.231 --> 00:23:56.668
Now imagine that we want to get
from the start point of this vector.

00:23:57.102 --> 00:24:00.272
Where we are
currently located to this store

00:24:00.539 --> 00:24:03.375
which is located over here.

00:24:03.375 --> 00:24:07.112
We know that there's a ten mile distance,
so we would just need to travel

00:24:07.412 --> 00:24:12.417
at ten miles per hour
But imagine this is a city

00:24:12.417 --> 00:24:16.054
and there's all these different blocks
and stores and buildings in the way.

00:24:16.254 --> 00:24:19.257
what if now we need to move in a square
grid like fashion?

00:24:19.257 --> 00:24:23.962
We can quickly see that
we need to travel east and then north.

00:24:24.696 --> 00:24:27.132
Now, if instead of east and north,

00:24:27.132 --> 00:24:31.636
we define east as the X direction
and north as the Y direction.

00:24:31.736 --> 00:24:35.273
Then we can see that we've broken down
our vector into two more simple

00:24:35.273 --> 00:24:38.276
vectors,
known as the components of our vector.

00:24:38.410 --> 00:24:41.379
This is kind of
what our G-code command is saying.

00:24:41.379 --> 00:24:45.684
It's like saying,
hey, move from this point to this X point

00:24:46.651 --> 00:24:48.086
and move from this y point

00:24:48.086 --> 00:24:51.122
to this y point, both at the same time.

00:24:51.923 --> 00:24:54.726
But it wants us to do it at a speed

00:24:54.726 --> 00:24:58.663
based on this distance
or our resultant vector.

00:24:58.663 --> 00:25:00.565
Is what that mean vector is called.

00:25:00.565 --> 00:25:04.069
So let's quickly work through an example
to see how this applies to our printer.

00:25:04.135 --> 00:25:07.405
Say that we start here
and we want our printer to move over

00:25:08.273 --> 00:25:11.042
to x equals 40.

00:25:11.042 --> 00:25:14.045
And we want the y axis to move up to

00:25:14.279 --> 00:25:16.081
y equals 30.

00:25:16.081 --> 00:25:18.149
So if we draw the resultant vector

00:25:18.149 --> 00:25:21.152
that starts from our start point
and ends at our end point,

00:25:21.520 --> 00:25:25.857
we can quickly find the length of that,
because we know that to get

00:25:25.857 --> 00:25:30.061
the length of that vector, we need to add
its components in quadrature.

00:25:30.695 --> 00:25:33.231
And I know that sounds kind of confusing,

00:25:33.231 --> 00:25:36.134
but this is basically
just Pythagoras theorem.

00:25:37.269 --> 00:25:39.671
If that's our A or B in our C,

00:25:39.671 --> 00:25:42.207
then we know that C is equal to the square

00:25:42.207 --> 00:25:45.210
root of A squared plus b squared.

00:25:45.777 --> 00:25:51.416
And in this case 40 and 30 I chose
because it comes out to a clean 50

00:25:51.516 --> 00:25:55.287
So if we want our
x move to take one second

00:25:55.987 --> 00:25:58.990
and we want our y move to take one second,

00:25:59.090 --> 00:26:03.261
then we would also want
our resultant vector to take one second.

00:26:03.962 --> 00:26:06.965
And knowing that our resultant vector

00:26:06.965 --> 00:26:09.968
is the value of 50,

00:26:10.001 --> 00:26:13.872
then we know that we would want to move
at 50 per second.

00:26:14.105 --> 00:26:15.574
Now this is truly brilliant.

00:26:15.574 --> 00:26:16.875
This is so cool.

00:26:16.875 --> 00:26:20.211
So let's say that
we want to play an A4 on our x axis,

00:26:20.812 --> 00:26:24.816
and we want to play an A3 on our y axis.

00:26:25.016 --> 00:26:28.219
And we want to play an A2 on the z axis.

00:26:28.386 --> 00:26:31.823
So if we want all of that
to take one second,

00:26:32.023 --> 00:26:36.061
we would want to move 176mm on the x axis.

00:26:36.194 --> 00:26:39.197
70.4mm along the y axis.

00:26:39.364 --> 00:26:42.667
And 8.8mm along the Z axis.

00:26:42.867 --> 00:26:44.569
Now it's a little harder
to wrap your head around

00:26:45.704 --> 00:26:48.440
because this is 3D space, not 2D space.

00:26:48.440 --> 00:26:51.142
But basically we're still using Pythagoras
theorem.

00:26:51.142 --> 00:26:54.946
We're just adding all these distances
up in quadrature to get that resultant

00:26:54.946 --> 00:26:55.914
vector length.

00:26:55.914 --> 00:26:58.516
So if we take the square root

00:26:58.516 --> 00:27:00.385
of all of these numbers squared.

00:27:00.385 --> 00:27:06.458
The resultant length
comes out to be about 189.76mm.

00:27:07.025 --> 00:27:10.028
So if we want to complete
this move in one second,

00:27:10.328 --> 00:27:15.700
we know that we would want to move
189.76mm per second.

00:27:16.067 --> 00:27:19.904
But again we need to multiply that by 60
which gives us

00:27:20.505 --> 00:27:26.411
11,385.72mm per minute.

00:27:27.746 --> 00:27:30.749
And that is our feed rate
that goes into our G-code command.

00:27:30.749 --> 00:27:36.221
So our resulting G-code
command should be G1 x 176.

00:27:36.621 --> 00:27:40.291
Y 70.4 Z 8.8.

00:27:40.425 --> 00:27:46.531
And remember, this is assuming that
we're starting at 000 for our x, y, and z.

00:27:46.531 --> 00:27:48.199
So we're basically homed.

00:27:48.199 --> 00:27:53.905
And then our feed rate again is 11,385.72.

00:27:54.272 --> 00:27:56.941
So let's go ahead
and put this into our printer

00:27:56.941 --> 00:28:00.745
and see if all three axes play these
three notes that we have defined.

00:28:05.583 --> 00:28:06.985
Oh, that's so great.

00:28:06.985 --> 00:28:10.989
We can play at least three different notes
at the same time.

00:28:11.489 --> 00:28:14.459
Now we just need to write some gcode
for our songs.

00:28:32.043 --> 00:28:32.477
Okay.

00:28:32.477 --> 00:28:37.282
So now all this ridiculous math is the
most time consuming part of the project.

00:28:37.382 --> 00:28:40.118
Calculating the speed
we need for different notes.

00:28:40.118 --> 00:28:45.123
Calculating how far we have to travel
for a certain rhythm in all three axes.

00:28:45.957 --> 00:28:49.828
Adding those axes up to get that full 3D
vector move to create G-code.

00:28:50.829 --> 00:28:53.064
I mean, that's a lot of work
for a single note.

00:28:53.064 --> 00:28:56.234
This took forever
for a single line of music, let alone

00:28:56.501 --> 00:28:58.703
an incredibly complex song.

00:28:58.703 --> 00:29:03.241
So I decided to write
some kind of musical programing language

00:29:03.241 --> 00:29:06.845
and write a script
to translate that into G-code.

00:29:07.245 --> 00:29:09.547
And this is what we got.

00:29:12.617 --> 00:29:15.620
Now presenting

00:29:18.690 --> 00:29:19.958
This is a script

00:29:19.958 --> 00:29:24.295
that takes in a musical programing
language and spits out G-code.

00:29:24.462 --> 00:29:27.899
This has gone through a lot of iterations,
tweaks and improvements,

00:29:27.899 --> 00:29:31.536
and I'd love to go over it, but I don't
want to relive that trauma right now.

00:29:31.970 --> 00:29:33.638
But we'll do a quick overview.

00:29:33.638 --> 00:29:37.342
If you want a deeper dive into the script,
I actually released another video

00:29:37.342 --> 00:29:40.111
at the same time as this one,
which takes a deeper dive into that.

00:29:40.111 --> 00:29:41.346
So check that out up here.

00:29:41.346 --> 00:29:44.215
Not only will that video dive deeper
into the actual programing,

00:29:44.215 --> 00:29:47.218
but I'll actually show you how to get it
set up on your end

00:29:47.252 --> 00:29:49.854
so that you can generate G-code
for your printer.

00:29:49.854 --> 00:29:52.791
But for now,
let's look at it from 10,000ft down.

00:29:52.791 --> 00:29:56.261
So I had three axes on my printer
that could play notes.

00:29:56.628 --> 00:29:59.364
So I decided to split these up
into three different things

00:29:59.364 --> 00:30:02.367
the melody, the mids and the bass.

00:30:02.433 --> 00:30:06.137
The x axis plays the melody as it's
capable of playing the higher notes.

00:30:06.905 --> 00:30:07.806
The z axis

00:30:07.806 --> 00:30:11.876
is the slower of all three axes,
so it plays the lowest notes or the bass.

00:30:12.343 --> 00:30:16.514
The y axis just kind of fills in
whenever the melody needs some harmony,

00:30:16.514 --> 00:30:19.484
or the bass needs some harmony,
because it can kind of play that midrange.

00:30:19.484 --> 00:30:22.053
So it does whatever I feel like it should.

00:30:22.053 --> 00:30:24.756
So the simplest way
I could think of creating

00:30:24.756 --> 00:30:28.560
this musical programing language
was to break down these things

00:30:28.560 --> 00:30:31.996
into three different files
the melody, the mid and the bass.

00:30:32.130 --> 00:30:34.966
This is what the inside
of one of those files looks like.

00:30:34.966 --> 00:30:36.000
Now don't be intimidated.

00:30:36.000 --> 00:30:37.969
These are a lot simpler than they seem.

00:30:37.969 --> 00:30:42.373
Basically, each line of this text file
represents a 16th note.

00:30:42.507 --> 00:30:47.345
The notes are typed in using their
official names, such as A4 or B-flat.

00:30:47.345 --> 00:30:47.979
Five.

00:30:47.979 --> 00:30:51.049
And these files are set up in such a way
that depending on how

00:30:51.049 --> 00:30:54.118
you type in these notes,
you can create different rhythms

00:30:54.118 --> 00:30:58.489
like a quarter note, a 16th out, or,
you know, even a dotted eighth note.

00:30:58.556 --> 00:31:02.493
The same goes for rests, which are just
represented by the letter R.

00:31:02.627 --> 00:31:06.164
So these three files are fed
into the script simultaneously,

00:31:06.164 --> 00:31:09.133
and it goes through all three
at once, one line at a time.

00:31:09.500 --> 00:31:13.304
And it generates a G-code which
will create those three notes at once.

00:31:13.571 --> 00:31:14.539
Now, getting into how

00:31:14.539 --> 00:31:18.476
you can have different rhythms on
the melody made and bass parts gets

00:31:18.476 --> 00:31:22.347
into the nitty gritty of the kinematics
equations that I set up in the script.

00:31:22.347 --> 00:31:25.650
So again, if you want to see that,
check that other video out.

00:31:25.717 --> 00:31:28.720
Now with this musical programing language
and this script,

00:31:29.053 --> 00:31:33.458
I was able to transcribe all of Fur Elise
and just a few hours.

00:31:33.691 --> 00:31:36.561
If you want to see the full
for at least video that's linked as well.

00:31:36.561 --> 00:31:39.597
so if you have a musical background,
you should be able to throw

00:31:39.597 --> 00:31:42.600
together a snippet from a song within
less than an hour.

00:31:42.700 --> 00:31:44.769
But if you don't have
a musical background,

00:31:44.769 --> 00:31:47.739
you might be looking at this
like it's some impossible task.

00:31:47.739 --> 00:31:50.708
And maybe it is
without some considerable effort.

00:31:50.708 --> 00:31:52.677
Unfortunately, that's just the reality.

00:31:52.677 --> 00:31:57.215
Luckily, if someone else
with a complete different printer writes

00:31:57.215 --> 00:32:01.419
a song that you want, they can give you
that melody, mid and bass file.

00:32:01.853 --> 00:32:05.490
And then you can run it through the script
and it will generate G-code

00:32:05.490 --> 00:32:07.125
specific to your printer.

00:32:07.125 --> 00:32:09.794
So I've uploaded this script
and the music files

00:32:09.794 --> 00:32:13.998
that I've created so far onto a GitHub
repository linked down in the description.

00:32:14.165 --> 00:32:18.403
My hope is that some of you watching
this video will create some music files,

00:32:18.403 --> 00:32:22.573
and request that I put them on the GitHub
repository so that others can share them.

00:32:22.807 --> 00:32:25.576
Not only is there a need for more music,
but honestly,

00:32:25.576 --> 00:32:28.146
the project needs to be further
developed as well.

00:32:28.146 --> 00:32:31.816
It's got a couple of limitations
and some quality of life improvements

00:32:31.816 --> 00:32:33.051
that could be made.

00:32:33.051 --> 00:32:34.686
So if you're interested in learning
about that

00:32:34.686 --> 00:32:37.956
and contributing in that way, then again,
check out the accompanying video.

00:32:38.389 --> 00:32:41.759
If you're interested in sharing the music
that you've made with this program,

00:32:41.759 --> 00:32:44.128
or you want to show off a cool project
you're working

00:32:44.128 --> 00:32:47.131
on, I've set up a discord server for this
channel.

00:32:47.131 --> 00:32:51.202
It's got a few different areas
for sharing songs, for sharing 3D prints,

00:32:51.202 --> 00:32:54.472
cool projects you're working on, mods
you've done to your printer,

00:32:54.505 --> 00:32:55.406
anything like that.

00:32:55.406 --> 00:32:56.774
Thank you so much for watching.

00:32:56.774 --> 00:32:59.777
As always, I hope you've learned something
from this video or

00:32:59.777 --> 00:33:02.780
something piqued your interest
and motivated you to do something.

00:33:02.981 --> 00:33:04.682
really excited to interact with you
all more,

00:33:04.682 --> 00:33:07.585
and I hope to see some of you
in the discord server soon.

00:33:07.585 --> 00:33:10.588
if I don't see you there, then I'll
make sure to catch you in the next video.

00:33:10.822 --> 00:33:15.093
So until then, I've been Spencer,
and I'll see you in the next one. Bye.

