polyphonic music player- Complete

This is a program i was working on you can play the 2 default songs or make your own. If any one knows a way i could save the song onto a text file then load it back in again that would be cool thanks to
volatile pulse
he helped me finish the program by fixing a couple of bug i didn't notice... here is the code post back any adjustments you make and any suggestions.

also the parameters for the PlayC() function are really long if some one knows a better way please post :D;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include<Windows.h>
#include<iostream>
#include <vector>
using namespace std;

	int A = 880;
	int B = 988;
	int C = 1047;
	int D = 1175;
	int E = 1319;
	int F = 1397;
	int G = 1568;
	int a = 440;
	int b = 494;
	int c = 532;
	int d = 587;
	int e = 659;
	int f = 699;
	int g = 784;

	int frth = 400;
	int one = 800;
	int half = 1600;
	int whole = 3200;
	void Pause()
	{
		char Ref;
		cin >> Ref;
	}
	int play(int note, int length)
{
	Beep(note,length);
	return 0;
}



	//mary had a little lamb function
void Mary()
{
	play(A,frth);
	play(g,frth);
	play(f,frth);
	play(g,frth);
	play(A,frth);
	play(A,frth);
	play(A,one);
	play(g,frth);
	play(g,frth);
	play(g,one);
	play(A,frth);
	play(C,frth);
	play(C,one);
	play(A,frth);
	play(g,frth);
	play(f,frth);
	play(g,frth);
	play(A,frth);
	play(A,frth);
	play(A,frth);
	play(A,frth);
	play(g,frth);
	play(g,frth);
	play(A,frth);
	play(g,frth);
	play(f,one);



}
void ode()
{
	play(B,one);
	play(B,one);
	play(C,one);
	play(D,one);
	play(D,one);
	play(C,one);
	play(B,one);
	play(A,one);
	play(g,one);
	play(g,one);
	play(A,one);
	play(B,one);
	play(B,one+frth);
	play(A,frth);
	play(A,half);
	



}
void playC(int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int n10,int n11,int n12,int n13,int n14,int n15,int L1,int L2,int L3,int L4,int L5,int L6,int L7,int L8,int L9,int L10,int L11,int L12,int L13,int L14
	,int L15)
{
	play(n1,L1);
	play(n2,L2);
	play(n3,L3);
	play(n4,L4);
	play(n5,L5);
	play(n6,L6);
	play(n7,L7);
	play(n8,L8);
	play(n9,L9);
	play(n10,L10);
	play(n11,L11);
	play(n12,L12);
	play(n13,L13);
	play(n14,L14);
	play(n15,L15);
}

int main()
{
	int Nn = 1;
	char noteC = 'C';
	char LengthC;
	int Note = 10;
	int Length = 800;
	int cust[15];
	int custl[15];
	int choice; // choice for main action
	char again = 'y';
	while(again == 'y')
	
	{
	
	cout << "Do you want to play mary had a little lamb or write your own music?\n" << endl;
	cout << "(1)Mary Had a Little Lamb" << endl;
	cout << "(2) Beethoven ode to joy" << endl;
	cout << "(3)Make Own Music(up to 15 notes)" << endl;
	cin >> choice;
	if (choice == 1)
	{
		Mary();
	}

	if (choice == 2)
	{
		ode();
	}
	
	
	if (choice == 3)
	{
		cout << "notes: a,b, c, d, e, f ,g\n";
		cout << "notes: A, B, C, D, E, F, G";
		cout << "lenght: r = fourth o = one beat h = half w = whole" << endl;cout << "EX: A one" << endl;
		for(int x = 0; x < 15; x++)
		{
			
		
		cout << "\nType a note" << Nn << ": ";
		
		cin >> noteC;
		cout << " length: ";
		cin >> LengthC;
		if(noteC == 'A'){Note = A;}
		
		if(noteC == 'B'){Note = B;}
		if(noteC == 'C'){Note = C;}
		
		if(noteC == 'D'){Note =D;}
		
		if(noteC == 'E'){Note = E;}

		if(noteC == 'F'){ Note = F;}
		
		if(noteC == 'G'){Note = G;}

		if(noteC == 'a'){Note = a;}
		
		if(noteC == 'b'){Note = b;}
		if(noteC == 'c'){Note = c;}
		
		if(noteC == 'd'){Note =d;}
		
		if(noteC == 'e'){Note = e;}

		if(noteC == 'f'){ Note = f;}
		
		if(noteC == 'g'){Note = g;}
		if (LengthC == 'r'){Length = frth;}
		if (LengthC == 'o'){Length = one;}
		if (LengthC == 'h'){Length = half;}
		if (LengthC == 'w'){Length = whole;}
		
		cust[x] = Note;
		custl[x] = Length;

		
		++Nn;
		
			}
		
		playC(cust[0],cust[1],cust[2],cust[3],cust[4],cust[5],cust[6],cust[7],cust[8],cust[9],cust[10],cust[11],cust[12],cust[13],cust[14],custl[0],custl[1],custl[2],custl[3],custl[4],custl[5],custl[6],custl[7],custl[8],custl[9],custl[10],custl[11],custl[12],custl[13],custl[14]);
		Pause();
		
	}
	cout << "do you want to do it again(y/n)" << endl;
	cin >> again; 
	}


		
	
	
	return 0;
}
Last edited on
PlayC(int n[15], int L[15])
Topic archived. No new replies allowed.