So I know that what I'm about to post seems like an insane amount of code for one post. Bear with me though, most of it is finished. I just need to get one or two things written correctly and it should work. Right now, I can't get my command object to use its data members to correctly call the respective method using the respective wav file. I've been playing around with the syntax and for the life of me can't seem to figure it out. I realize that some of the code I have isn't working correctly, namely the Double(), Half(), Mix(), Reverse(), and Echo() methods all have inconsistencies or flat-out malficiencies. My focus right now though is to get the command class object, with the user's input, and use that data to call the correct method and use the right wav file.
EDIT: What you'll see is I have a wav class, that handles creating the wav files. Then I have a WavContainer class that holds and "manages" a number of wav files. And then I've got the command class that creates an object to handle the user's input. I need to use the command object's data to call the methods to do stuff to the pertaining wav file and wav method.
#include <iostream>
#include <string>
#include <cstdlib>
usingnamespace std;
#include "wav.h"
#include "WavContainer.h"
class command
{
public:
string option, newSound;
int place, placeTwo;
WavContainer wave;
command();
void input();
int selection(WavContainer &waveCont);
};
command::command()
{
option = "";
newSound = "";
place = 0;
placeTwo = 0;
}
void command::input()
{
string input; // Holds the user's input for parsing.
cout << "cmd> ";
string peek = ""; // String to hold the first character in input
int blankCnt = 0; // Used in case the for loop encounters spaces in string input.
getline(cin, input); // Gets the user's input from the cin
for(unsignedint i=0;i<input.length();i++)
{
peek = input[ i ]; // gets the first character in the input string, stores in peek
if(peek != " ") // if its a blank
{
if((peek >= "a") && (peek <= "z")) //if its a letter between a -> z
{
if(blankCnt == 0) // if its a blank, increases count
option.append( peek ); // appends the char in peek to the option string
else
newSound.append( peek ); //if it hits a space, starts storing in the newSound string
}
elseif((peek >= "1") && (peek <= "9")) // if it hits a number
{
if((place >= 1) && (place <= 9)) // if place has a number in it
placeTwo = atoi( peek.c_str() ); // stores in placeTwo
else // if not, stores in place
place = atoi( peek.c_str() );
}
}
else
blankCnt++; // increments blankCnt
}
// COUT CHECK
cout << "option: " << option << endl
<< "place: " << place << endl
<< "placeTwo: " << placeTwo << endl
<< "newSound: " << newSound << endl;
}
int command::selection(WavContainer &waveCont) // NOT DONE, DOESN'T CALL THE METHODS
{
int pos;
pos = waveCont.GetPos();
// Use the prompt object to call the methods
if(option == "play")
{
cout << "PLAY" << endl;
//CALL THE PLAY METHOD
// USE THE PLACE INT TO CALL PLAY METHOD ON RIGHT WAV
return pos;
}
elseif(option == "delete")
{
cout << "DELETE" << endl;
//CALL THE DELETE METHOD
}
elseif(option == "reverse")
{
cout << "REVERSE" << endl;
//CALL THE REVERSE METHOD
}
elseif(option == "half")
{
cout << "HALF" << endl;
//CALL THE HALF METHOD
}
elseif(option == "double")
{
cout << "DOUBLE" << endl;
//CALL THE DOUBLE METHOD
}
elseif(option == "mix")
{
cout << "MIX" << endl;
//CALL THE MIX METHOD
}
}
int main()
{
// Create the wav container with the initial amount of wav files
WavContainer waves( 6 );
// Get the wav files
Wav cde("sounds\\cde.wav");
Wav crow("sounds\\crow.wav");
Wav door("sounds\\door.wav");
Wav luke("sounds\\luke.wav");
Wav water("sounds\\water.wav");
Wav welcome("sounds\\welcome.wav");
//checks to test the wav effects
door.Play();
//door.Reverse();
//door.Half();
//door.Double();
//door.Mix();
//door.Echo();
// Add the wav files to the container
waves.Add(cde);
waves.Add(crow);
waves.Add(door);
waves.Add(luke);
waves.Add(water);
waves.Add(welcome);
// Checks to see what is added and how big it is
cout << "There are " << waves.Size() << " wave files to use." << endl << endl;
// CALL THE SHOW SELECT FUNCTION
cout << "Selection: " << endl;
waves.Show();
// COUT FOR STRING TO SELECT
command prompt;
prompt.input();
int pos;
pos = prompt.selection( waves );
return 0;
system("pause");
}
command functions by creating an object with four data members. it parses a string that holds what is put on the istream. The command class is used to get the users input. It is purely used for that. What the rest is simple.
What I want to do is ask the user what he wants to do. Then once I get the user telling me what to do, I would like to use that input stored in a command object, and use it as parameters for calling methods in my wav class. The problem I'm having is the fact that command has no connection with WavContainer or the wav classes. Its unable to handle anything from the command class. So when I want to use the first data member in command, option, and use that in a method to call the correct method in wav class. Its really complicated so I'll apologize ahead of time for the nonsense. I'm trying my best to keep it as simple as possible.
Comments like that make code harder to read, and you've already posted far more code than you needed to.
If I understand what you're asking for it's help implementing the command::selection function, which you've made no attempt to do other than writing a few comments?
So for "Play" inside your selection command, based on the users input data, call waveCont.Play(userselectedInput);
What is the question again?
You need to modifier your container to give you the interface command can use to do what you need. Either modify the container directly, or create an interface that the container inherits from and implements those methods (google adapter pattern)... you have the code there, you know what you want to be able to pass as parameters, just create the interface for it.