I
inkexit
I am a very amatuer c++ programmer and a somewhat accomplished
composer. I am trying to write some code that creates 'self similar'
melodies from a base melody the user inputs. This musical idea was
created by Tom Johnson. Apologies to those who are not musically
literate, but as this is basically a mathmatical problem I think most
here can follow the logic.
Lets keep eveything in C Major, that's all the white keys on the piano.
Being as that we are in C Major, the note C will be our base note.
So:
C=0
D=1
E=2
F=3
G=4
A=5
B=6
(next octave up)
C=7
D=8
E=9
F=10
G=11
A=12
B=13
etc...
Using this, we can enter a base melody:
0, 5, 6, 4, 1, 2, 5, 0
The idea of creating self similar melodies is to take all the intervals
(the distance inbetween the neighboring notes) and double them. So,
from this base melody, the first iteration would be:
0, 10, 12, 8, 2, 10, 0
next iteration:
0, 20, 24, 16, 4, 20, 0
etc...
So anyway, here's my code. It won't compile. Please help, and thanks
for wading through this.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void exp_melod_self_similar(int [], int);
int main()
{
int note_number = 1;
int melod_length;
cout << "Enter length of melody in 1/8 notes:";
cin >> melod_length;
int base_melod[melod_length];
do
{
cout << "note " << note_number;
cin >> base_melod[note_number];
note_number++;
}
while (note_number < melod_length);
exp_melod_self_similar(base_melod, melod_length);
return 0;
}
void exp_melod_self_similar(int new_melod[], int melod_length)
{
int new_melod[];
new_melod[0] = base_melod[0];
for (i=1, i<=melod_length, i++)
{
new_melod = base_melod * 2;
cout << new_melod;
}
}
composer. I am trying to write some code that creates 'self similar'
melodies from a base melody the user inputs. This musical idea was
created by Tom Johnson. Apologies to those who are not musically
literate, but as this is basically a mathmatical problem I think most
here can follow the logic.
Lets keep eveything in C Major, that's all the white keys on the piano.
Being as that we are in C Major, the note C will be our base note.
So:
C=0
D=1
E=2
F=3
G=4
A=5
B=6
(next octave up)
C=7
D=8
E=9
F=10
G=11
A=12
B=13
etc...
Using this, we can enter a base melody:
0, 5, 6, 4, 1, 2, 5, 0
The idea of creating self similar melodies is to take all the intervals
(the distance inbetween the neighboring notes) and double them. So,
from this base melody, the first iteration would be:
0, 10, 12, 8, 2, 10, 0
next iteration:
0, 20, 24, 16, 4, 20, 0
etc...
So anyway, here's my code. It won't compile. Please help, and thanks
for wading through this.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void exp_melod_self_similar(int [], int);
int main()
{
int note_number = 1;
int melod_length;
cout << "Enter length of melody in 1/8 notes:";
cin >> melod_length;
int base_melod[melod_length];
do
{
cout << "note " << note_number;
cin >> base_melod[note_number];
note_number++;
}
while (note_number < melod_length);
exp_melod_self_similar(base_melod, melod_length);
return 0;
}
void exp_melod_self_similar(int new_melod[], int melod_length)
{
int new_melod[];
new_melod[0] = base_melod[0];
for (i=1, i<=melod_length, i++)
{
new_melod = base_melod * 2;
cout << new_melod;
}
}