0

hi there im having some problems, im trying to write a simple software sequencer in visual C++ under windows. I have a few problems my first two menus open up fine but the third wont open it just loops on the title menu. The second probelm i have is that all the sections dont play together any help would be great cheers ontrix code attached

Attachments
#include "BeeThree.h" // Include first instrument
#include "Plucked.h" // Include second instrument
#include "TubeBell.h" // Include third instrument
#include "FMVoices.h"// Include forth instrument
#include "Whistle.h" // Include fith instrument
#include "RtWvOut.h" // Include header information for playing back a sample
#include <conio.h> // Include the get function  
#include "BeeThree.h" // Include first instrument
#include "Plucked.h" // Include second instrument
#include "TubeBell.h" // Include third instrument
#include "FMVoices.h"// Include forth instrument
#include "Whistle.h" // Include fith instrument
#include "RtWvOut.h" // Include header information for playing back a sample
#include "RtWvOut.h" // Include header information for playing back a sample

// Header information for real-time MIDI Input
#include "RtMidi.h"
#include "SKINI.h"
#include "Utilities.h"



int main()
{
	//----------bass part--------------------------------------------------

  int i; // This variable will be used to count the output samples
  float frequency[5]; // This variable holds the frequencys of the note
  float duration[5]; // holds note duration
  char menu;// first menu choice
  char menu2;// second menu choice
  
  int this_note; // The current note that we're dealing with inside the array frequency
  int this_frequency; // the current frequency
  int this_duration; // the current duration
  int num_notes=20; // how many note to be played
  int edit_note; // which note you wish to edit
  int edit_duration; // which duration you wish to edit
  float edit_instrument[5]; //edit the instrument for a note
  Instrmnt *instrument = 0; // This variable will hold the instrument information
  RtWvOut *output = 0; // This variable will hold output samples
  //-------------melody part------------------------------------------------

  float frequency1[5]; // This variable holds the frequencys of the note
  float duration1[5]; // holds note duration
  char menu3;// third menu choice
  char menu4;// fourth menu choice
  int this_note1; // The current note that we're dealing with inside the array frequency
  int this_frequency1; // the current frequency
  int this_duration1; // the current duration
  int num_notes1=20; // how many note to be played
  int edit_note1; // which note you wish to edit
  int edit_duration1; // which duration you wish to edit
  float edit_instrument1[5]; //edit the instrument for a note
  Instrmnt *instrument1 = 0; // This variable will hold the instrument information
  //--------------rhythem part-----------------------------------------------

  float frequency2[5]; // This variable holds the frequencys of the note
  float duration2[5]; // holds note duration
  int this_note2; // The current note that we're dealing with inside the array frequency
  int this_frequency2; // the current frequency
  int this_duration2; // the current duration
  int num_notes2=20; // how many note to be played
  int edit_note2; // which note you wish to edit
  int edit_duration2; // which duration you wish to edit
  float edit_instrument2[5]; //edit the instrument for a note
  Instrmnt *instrument2 = 0; // This variable will hold the instrument information
  

  Stk::setSampleRate( 22050.0 ); // Set a sampling rate

  instrument = new BeeThree; // Use BeeThree instrument for bass part
  instrument1 = new BeeThree; // Use BeeThree instrument for melody part
  instrument2 = new BeeThree; // Use BreeThree instrument for rhythem part
  output = new RtWvOut(1); // Set up the audio output



  for (i=0; i<5; i++)
  {
	
	frequency[i] = 100; // temp frequency
	duration[i] = 1000; // temp duration
  }

  menu = '0';
  while (menu !='6')
{
//menu
	cout << "----------------------"<<endl;
	cout << "1: edit the bass part"<< endl;
	cout << "2: edit the melody part" << endl;
	cout << "3: edit the rhythem part" << endl;
	cout << "4: play all parts" << endl;
	cout << "5: pratice playing" << endl;
	cout << "6: exit" << endl ;


	menu=getch();

//-------------------------------------------------------------------
// bass parts

//--------------------------------------------------------------------

	if (menu == '1')
	{
  
		menu2 = '0';
  

		{

	  
    //  menu
			cout << "bass part" <<endl;
			cout << "----------------------------" << endl;
			cout << "1: Play note sequence" << endl;
			cout << "2: number of notes" << endl;
			cout << "3: Edit indivisual note frequency"<< endl;
			cout << "4: Edit indivisual duration" << endl;
			cout << "5: Edit instrument" <<endl;
			cout << "6: Change note frequencies " << endl;
			cout << "7: Change duration of notes " << endl;
			cout << "8: Quit" << endl;

			menu2=getch();
	
    //----------------------------------------------------------------
    

			if (menu2 == '1') // Play the note
			{
			
					
					cout << "Menu option 1" << endl;
		 
					for (this_note=0;this_note<num_notes;this_note++)// current note in the array
					{
						for (i=0; i<5;i++)
						{
							if (edit_instrument[i] == 1)
							{
								delete instrument;
								instrument = new Plucked(50); // Use the plucked instrument
							}
							if (edit_instrument[i] == 2)
							{
								delete instrument;
								instrument = new TubeBell(); // Use the tubebell instrument 
							}
							if (edit_instrument[i] == 3)
							{
								delete instrument;
								instrument = new FMVoices(); // Use the formswep instrument 
							}
							if (edit_instrument[i] == 4)
							{
								delete instrument;
								instrument = new Whistle (); // use the whistle instrument
							}
		
							instrument->noteOn( frequency[this_note],0.5 ); // Play note
							cout << "Playing note " << this_note << " frequency " << frequency[this_note] << endl;
		
							for (i=0; i<duration[this_note]; i++ ) // Output samples to play note
							{
		
								output->tick( instrument->tick() );

							}
		
							instrument->noteOff( 1.0 ); // Turn note off

							for (i=0; i<10000; i++) // Output samples as note fades away
							{
								output->tick( instrument->tick() );
							}
						}

					}
			
			
		}
	}
	
//--------------------------------------------------------------
// play all parts
		
				if (menu =='4')
				{	
					cout << "Menu option 1" << endl;
		 
					for (this_note=0;this_note<num_notes;this_note++)// current note in the array
					{
						for (i=0; i<5;i++)
						{
							if (edit_instrument[i] == 1)
							{
								delete instrument;
								instrument = new Plucked(50); // Use the plucked instrument
							}
							if (edit_instrument[i] == 2)
							{
								delete instrument;
								instrument = new TubeBell(); // Use the tubebell instrument 
							}
							if (edit_instrument[i] == 3)
							{
								delete instrument;
								instrument = new FMVoices(); // Use the formswep instrument 
							}
							if (edit_instrument[i] == 4)
							{
								delete instrument;
								instrument = new Whistle (); // use the whistle instrument
							}
		
							instrument->noteOn( frequency[this_note],0.5 ); // Play note
							cout << "Playing note " << this_note << " frequency " << frequency[this_note] << endl;
		
							for (i=0; i<duration[this_note]; i++ ) // Output samples to play note
							{
		
								output->tick( instrument->tick() );

							}
		
							instrument->noteOff( 1.0 ); // Turn note off

							for (i=0; i<10000; i++) // Output samples as note fades away
							{
								output->tick( instrument->tick() );
							}
						}

					}
				}
		
//----------------------------------------------------------------------------------------------		
		
		
		
		
		// choose how many notes you would like

				if (menu2 == '2')
			{
				cout << "-----------------------------------------" <<endl;
				cout << "how many notes " <<endl;

				cin >> num_notes;
			}
    // --------------------------------------------------------------
	// which note frequency to edit
			if (menu2 == '3')
			{			cout << "--------------------------------------------"<<endl;
						cout << "which note frequency would you like to edit" <<endl;
						cin >> edit_note;
						cout << "Enter new value for note " << edit_note << endl;
						cin >> frequency[edit_note];
						
				
			}
		
			

	//---------------------------------------------------------------
// which duration would you like to edit
			if (menu2 == '4')
			{
				cout << "------------------------------------------" <<endl;
				cout << "which note duration would you like to edit" <<endl;
				cin >> edit_duration;
				cout << "enter new value for duration" <<endl;
				cin >> duration[edit_duration];
			}
	  

	//----------------------------------------------------------------
//which note instrument would you like to edit
			if (menu2 == '5')
			{
				cout <<"---------------------------------------------" <<endl;
				cout <<"which instrument would you like to change to" <<endl;
				cout << "1: plucked" <<endl;
				cout << "2: tubebell" <<endl;
				cout << "3: fmvoices" <<endl;
				cout << "4: whistle" <<endl;
				cin >> edit_instrument[i];
			
			}
		
	
	//----------------------------------------------------------------

			if (menu2 == '6') // Enter new frequency of note
			{
				cout << "--------------------------------------------------------" << endl;

				for (this_frequency=0; this_frequency<num_notes;this_frequency++)// current frquency 
			{
				cout << "Enter new frequency " << endl;
				 cin >> frequency[this_frequency];
			}

			}
	

    // --------------------------------------------------------------

			if (menu2 =='7')// enter duration of note
			{
				cout << "-----------------------------------------------" << endl;

			for (this_duration=0; this_duration<num_notes;this_duration++)// current duration
			{
				cout << "enter new duration " << endl;
				cin >> duration[this_duration];
			}
			} 
			}
  //--------------------------------------------------------------------
  // melody par
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Salem
0

You really need to discover the magic of
a) indentation
b) functions.

A 800+ lines of code in main(), c'mon be serious.
Nobody is going to wade through that lot just to spot what might be wrong.

A rough rule of thumb - if you can't see the entire function on screen at the same time (from it's opening brace to it's closing brace), then it's probably too big to manage.

I bet all those header files have code inside them as well right?

How about a separate function for each top-level menu choice.

>> snipped from the code...

float edit_instrument1[5]; //edit the instrument for a note
  Instrmnt *instrument1 = 0; // This variable will hold the instrument information
  // snip
  float edit_instrument2[5]; //edit the instrument for a note
  Instrmnt *instrument2 = 0; // This variable will hold the instrument information

Why isn't this screaming at you to be
a) a struct containing several things
b) an array of that struct.
That would cut down significantly on the number of variables you have.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.