/*
 * Fixed Gear Mixer
 * playlist maker for rhythmic bike riding
 * Copyright (c) Becky Stern and Kate Garaufis 2006 * licenced under the MIT Software license * viewable at: http://www.opensource.org/licenses/mit-license.php * stern[at]parsons[dot]edu
 */

//begin Stern code
#include <iostream>
#include <cstring>
#include <string>

class Song {
private:
	char songname[30];
	char artistname[30];
	
public:
	int BPM;
	int songlength;
	void initialize(const char * co, const char * ca, int n, int pr);
	void show();

};

void Song::initialize(const char * co, const char * ca, int n, int pr) {
	std::strncpy(songname, co, 29); //truncate co to fit songname
	std::strncpy(artistname, ca, 29); //truncate co to fit artistname
	songname[29] = '\0';
	artistname[29] = '\0';
	if (n < 0) {
		std::cerr << "Number of BPM can't be negative; " << songname << " BPM set to 0.\n";
		BPM = 0;
	}
	else {
		BPM = n;
		songlength = pr;
	}
}

void Song::show() {
	using std::cout;
	using std::endl;
	cout << "Song Name: " << songname << " Artist Name: " << artistname << " BPM: " << BPM <</* " Song Length: " << songlength << */endl;
	//cout << "Other BPMs: " << endl;
	//for (int i=0; i < 21; i++){
	//	cout << BPMs[i] << endl;
	//}
}
//int* matchup(int matchme) {
//	return(matches);
//}

	Song songs[22];

	
int main() {
	using namespace std;
	using std::ios_base;
	int databasesize = 43;
//pause Stern code	
//begin garaufis code	
//variables

int frontTeeth, cogTeeth;
float gearInches, wheelDiameter, gearMiles, rpm, speedMilesPerMinute, speedMilesPerHour, distancePerRotation, tripMiles, tripTime;


//kate's iro
//wheelDiameter = 26.57;
//frontTeeth = 46;
//cogTeeth = 16;

//user input

cout<<endl<<"Welcome to Fixed Gear Mixer! We're going to help you devise a rhythmically synced playlist for riding your bike."<<endl;
cout<<"First, let's calculate your Gear Inches."<<endl;
cout<<"Enter your wheel's diameter, including the tire. (26.57 is a good bet for road or track bikes.)"<<endl;
cin>>wheelDiameter;
cout<<"Count the teeth on your front chainring."<<endl; //kate's is 46
cin>>frontTeeth;
cout<<"Count the teeth on your rear cog."<<endl; //kate's is 16
cin>>cogTeeth;


gearInches = (wheelDiameter * frontTeeth) / cogTeeth;
cout<<"You're pushing "<<gearInches<<" gear inches."<<endl;

cout<<"Would you like to calculate based on enter target speed, or specific trip distance/time?"<<endl;
//cout<<"Enter s for speed, t for trip"<<endl;

char selection;

cout<<"Please enter one of the following choices:"<<endl;
cout<<"s) enter target speed "       <<endl;
cout<<"t) enter trip distance and target time"<<endl;

	cin>>selection;

for(;;){

	if (selection=='s'){
		cout<<"enter a target speed in mph"<<endl;
		cin>>speedMilesPerHour;
		

		gearMiles = gearInches / 63360;
		speedMilesPerMinute = speedMilesPerHour / 60;
		distancePerRotation = gearMiles * 3.1416;

		rpm = speedMilesPerMinute/distancePerRotation;

		//rpm = speedMilesPerMinute/(gearMiles * 3.1416);

		cout<<"To go "<<speedMilesPerHour<<" mph, you need to pedal "<<rpm<< " rotations per minute."<< endl << endl << "Here is your playlist:" << endl;


	break;
		}
		
	else if (selection=='t'){
		cout<<"enter the distance of your trip, in miles"<<endl;
		cin>>tripMiles;	
		cout<<"enter the amount of time you'd like the trip to take, in minutes."<<endl;
		cin>>tripTime;	
		tripTime = (tripTime*.75);
		speedMilesPerHour = tripMiles/(tripTime / 60);
		
		gearMiles = gearInches / 63360;
		speedMilesPerMinute = speedMilesPerHour / 60;
		distancePerRotation = gearMiles * 3.1416;

		rpm = speedMilesPerMinute/distancePerRotation;

		//rpm = speedMilesPerMinute/(gearMiles * 3.1416);

		cout<<"Assuming you spend one quarter of that time stopped or slowed in city traffic, to go "<<tripMiles<<" miles in "<<tripTime<< " minutes is a speed of "<<speedMilesPerHour<<" miles per hour."<< endl;
		cout<<"To go "<<speedMilesPerHour<<" mph, you need to pedal "<<rpm<< " rotations per minute."<< endl << endl << "Here is your playlist:" << endl;

		
		
		break;
		}
		
	else{
	cout<<"Please enter s or f:"<<endl;
	cin>>selection;
		}
	}
	//end Garaufis code
	//resume Stern code
	
	
	//int* matchup(int matchme);
	
	//Song *ps;
	//Song database
	songs[0].initialize("Personal Jesus", "Depeche Mode", 130, 296);
	songs[1].initialize("Sugar Sugar", "The Archies", 62, 174);
	songs[2].initialize("Dude (Looks Like A Lady)", "Aerosmith", 63, 264);
	songs[3].initialize("Sabotage", "Beastie Boys", 84, 178);
	songs[4].initialize("Walk Like an Egyptian", "Bangles", 103, 204);
	songs[5].initialize("Need You Tonight", "INXS", 109, 204);
	songs[6].initialize("Everybody Dance Now", "C & C Music Factory", 114, 248);
	songs[7].initialize("Don't You Want Me", "Human League", 117, 239);
	songs[8].initialize("Sweet Dreams (Are Made of This)", "Eurythmics", 125, 217);
	songs[9].initialize("Rock The Casbah", "The Clash", 129, 220);
	songs[10].initialize("St. Louise Is Listening", "Soul Coughing", 182, 269);
	songs[11].initialize("Sweet Home Alabama", "Lynyrd Skynyrd", 98, 283);
	songs[12].initialize("Walk Like an Egyptian", "Bangles", 103, 204);
	songs[13].initialize("Travellers Tune", "Ocean Colour Scene", 135, 218);
	songs[14].initialize("Jump, Jive An' Wail", "Brian Setzer Orchestra", 201, 173);
	songs[15].initialize("Walk Like an Egyptian", "Bangles", 103, 204);
	songs[16].initialize("Not If You Were The Last Junkie On Earth", "The Dandy Warhols", 115, 191);
	songs[17].initialize("Born To Run","Bruce Springsteen", 148, 270);
	songs[18].initialize("Temperature","Sean Paul", 128, 212);
	songs[19].initialize("Rock Lobster","The B-52's", 183, 412);
	songs[20].initialize("Bombs Over Baghdad","Outkast", 154, 304);
	songs[21].initialize("Let's Hear It For The Boy","Cyndi Lauper", 121, 208);

	//these songs do not have length data at this juncture
	songs[19].initialize("Dude Looks Like a Lady","Aerosmith", 128, 4);
	songs[20].initialize("Artistiya","Amadou & Mariam", 218, 4);
	songs[21].initialize("Further","Autechre", 111, 4);
	songs[22].initialize("Sure Shot","Beastie Boys", 98, 4);
	songs[23].initialize("Cellphone's Dead","Beck", 108, 4);
	songs[24].initialize("4 Easy","The Beta Band", 168, 4);
	songs[25].initialize("Paris","Carina Round", 87, 4);
	songs[26].initialize("Over and Over Again (Lost & Found)","Clap Your Hands Say Yeah!", 138, 4);
	songs[27].initialize("Oliver's Army","Elvis Costello", 143, 4);
	songs[28].initialize("Hella Nervous","Gravy Train", 142, 4);
	songs[29].initialize("Personal Jesus","Johnny Cash", 123, 4);
	songs[30].initialize("We Share Our Mothers Health (Trentemoller Remix)","The Knife", 123, 4);
	songs[31].initialize("Love at First Sight","Kylie Minogue", 125, 4);
	songs[32].initialize("United States of Whatever","Liam Lynch", 164, 4);
	songs[33].initialize("Desaparecido","Manu Chao", 98, 4);
	songs[34].initialize("Mr Bobby","Manu Chao", 150, 4);
	songs[35].initialize("The Way You Move","Outkast", 126, 4);
	songs[36].initialize("This Is Love","P.J. Harvey", 112, 4);
	songs[37].initialize("The Immigrant","The Prodigals", 128, 4);
	songs[38].initialize("Another One Bites the Dust","Queen", 110, 4);
	songs[39].initialize("Good People Check","Themselves", 90, 4);
	songs[40].initialize("All McGyver On It","They Might Be Giants", 185, 4);
	songs[41].initialize("Wolf Like Me","TV On The Radio", 123, 4);
	songs[42].initialize("Personal Jesus","Johnny Cash", 175, 4);
	
			
	int matches[databasesize];
	int BPMs[21];

	cout.setf(ios_base::fixed);
	cout.precision(2);
	cout.setf(ios_base::showpoint);
	
	int matchme = int(rpm);
	//int *returned;
	//returned = matchup(queryBPM);
	BPMs[0] = matchme;
		BPMs[1] = int(matchme / 2);
		BPMs[2] = (matchme * 2);
		for (int i=3; i < 6; i++){			//create array of values to match BPM/cadence to
			BPMs[i] = (matchme + i + 1);		//+3
			BPMs[i+3] = (matchme - i - 1);		//-3
			BPMs[i+6] = int(matchme/2 + i + 1);	//half + 3
			BPMs[i+9] = int(matchme/2 - i - 1);	//half - 3
			BPMs[i+12] = int(matchme*2 + i + 1);	//double - 3
			BPMs[i+15] = int(matchme*2 - i - 1);	//double - 3
		}
	int numOfMatches = 0;
	for (int i=0; i < 21; i++){
		for (int j=0; j < databasesize; j++){
			if (BPMs[i] == songs[j].BPM){
				matches[numOfMatches] = j;
				numOfMatches++;
				songs[j].show();
			}
		}
	}
	if (numOfMatches == 0){
			cout << "Your trip returned zero songs." << endl;
		}
	cout << endl;
	
	return 0;
}