|
-
January 11th, 2017, 08:49 AM
#1
How can I use my current code to prompt the computer to output back a series of MIDI
I'm still new to C++ so im still trying to get my head around a few things. All my validation works fine. The user must input a MIDI note that consists of at 2-3 characters, be between A-G, the last character must be a digit, and if the length is 3 the middle character must be a sharp(#).
What I must do now is allow the user to enter a series of notes for both MELODY and BASS, to then store them, to then output them back to the user in order they entered them. At the moment the user can only enter 2 notes before the program closes itself. What should I do?
Code:
using namespace std;
#include <iostream>
#include <cstdlib>
using namespace std;
//********START UP MENU*******//
int StartUpMenu()
{
while (1)
{
int choice;
cout <<"::menu option::\n\n"
<<"1. Bass\n"
<<"2. Melody\n"
<<"3. Exit\n"
<<"Would you like to work with Bass or Melody first? Please enter 1 for Bass or 2 for Melody or 3 to Exit:";
cin >> choice;
if(choice == 3) break;
else if (choice == 1)
{
system ("CLS");
cout<<"1. Bass \n\n";
system ("PAUSE");
system ("CLS");
}
else if (choice == 2)
{
system ("CLS");
cout<<"2. Melody \n\n";
system ("PAUSE");
system ("CLS");
}
else if (choice > 3 || choice < 1)
{
system ("CLS");
cout<<"2. Melody \n\n";
system ("PAUSE");
system ("CLS");
}
}
return 0;
}
//********VALIDATION FOR NOTE NAME********//
string GetNote()
{
string input;
int loop = 1;
cout << "Hello, please type in a note: "<< endl;
cin >> input;
while (loop < 5000)
{
if (input.length() < 2 || input.length() > 3) //Step 1: If note name length is less than 2 OR more than 3, return false
{
cout<<"Note must be either 2 or 3 characters long!\n";
cin >> input;
}
else if (((int)input[0] < 65)|| ((int)input[0] > 71 )) //Step 2: The note must be/(or be) between A and G
{
cout<<"The note must be between A to G!\n";
cin >> input;
}
else if (input.length() == 2 && (isdigit(input[1]) == false))
//(isdigit(note[GetValidNote()-1]) == false) //Step 3: If true, the last character must be a digit
{
cout<<"Last character must be a digit!\n";
cin >> input;
}
else if (input.length() == 3 && (isdigit(input[2]) == false))
//(isdigit(note[GetValidNote()-1]) == false) //Step 3: If true, the last character must be a digit
{
cout<<"Last character must be a digit!\n";
cin >> input;
}
else if (input.length() == 3 && input[1] !='#') //Step 4: If note length is 3 note[1] (character 2) must be '#'.
{
cout<<"Invalid sharp note\n";
cin >> input;
}
else
{
return input;
}
}
}
//********GET MIDI********//
int MidiStorage(string validnote)
{
int MidiLetter = validnote[0] - 65;
int Note;
int Octave = validnote[validnote.length()-1]; //THIS IS A MATHMATICAL EQUATION TO GET THE COMPUTER TO REALISE WHAT AN OCTAVE IS USING THE MIDI NOTE CHART.
if(validnote[0] == 'A')
{
MidiLetter = 9;
}
else if (validnote[0] == 'B')
{
MidiLetter = 11;
}
else if (validnote[0] == 'C')
{
MidiLetter = 12;
}
else if (validnote[0] == 'D')
{
MidiLetter = 14;
}
else if (validnote[0] == 'E')
{
MidiLetter = 16;
}
else if (validnote[0] == 'F')
{
MidiLetter = 17;
}
else if (validnote[0] == 'G')
{
MidiLetter = 19;
}
/////////////////////
int midivalue = MidiLetter + (Octave * 12);
if(validnote.length() == 3)
{
midivalue += 1;
}
}
//Validation
int main()
{
string note;
int midivalue;
StartUpMenu(); //This function brings you to the start up menu
note = GetNote(); //This function tells the computer what note between A-G and the user has given
cout << "The note you chose is: " << note << endl;
MidiStorage(note);
GetNote();
return 0;
}
Last edited by 2kaud; January 11th, 2017 at 09:02 AM.
Reason: Code tags added
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|