C++ Music Maker



  • 😃 da ich mal wieder zuviel freizeit hatte kam dabei folgendes raus

    #include <iostream>
    #include <windows.h>
    #include <fstream>
    #include <stdexcept>
    #include <stdio.h>
    
    #define VK_a  65 
    #define VK_b 66 
    #define VK_c 67 
    #define VK_d 68 
    #define VK_e 69 
    #define VK_f 70 
    #define VK_g 71 
    #define VK_h 72 
    #define VK_i 73 
    #define VK_j 74 
    #define VK_k 75 
    #define VK_l 76 
    #define VK_m 77 
    #define VK_n 78 
    #define VK_o 79 
    #define VK_p 80 
    #define VK_q 81 
    #define VK_r 82 
    #define VK_s 83 
    #define VK_t 84 
    #define VK_u 85 
    #define VK_v 86 
    #define VK_w 87 
    #define VK_x 88 
    #define VK_y 89
    #define VK_z 90 
    #define VK_F1 112 
    
    using namespace std;
    
    int main()
    {
    
        cout<<"Patrick Ratzs C++ Music-Maker v.1.01\n\n";
        cout<<"-----------------------------------\n";
        cout<<"Help = F1\n\n\n\n";
    
        char line[256];
        fstream datei;
        datei.open("C://music.txt", ios::out);
        datei << "#include <iostream>\n";
        datei << "#include <windows.h>\n\n";
        datei << "using namespace std;\n";
        datei << "int music()\n{"<<endl;
    
    while(1){
    
    if (GetAsyncKeyState(VK_a) &1 )
    {
     cout<<"c";
     datei << "Beep(264,100);"<<endl; 
     datei << "Sleep(100);"<<endl;                        
     Beep(264,100); //c
    }
    
    if (GetAsyncKeyState(VK_s) &1 )
    {
     cout<<"d";
     datei << "Beep(297,100);"<<endl;
     datei << "Sleep(100);"<<endl;
     Beep(297,100); //d
    }
    
    if (GetAsyncKeyState(VK_d) &1 )
    {
     cout<<"e";
     datei << "Beep(330,100);"<<endl; 
     datei << "Sleep(100);"<<endl;                        
     Beep(330,100); //e
    }
    
    if (GetAsyncKeyState(VK_f) &1 )
    {
     cout<<"f";
     datei << "Beep(352,100);"<<endl;
     datei << "Sleep(100);"<<endl;
     Beep(352,100); //f
    }
    
    if (GetAsyncKeyState(VK_g) &1 )
    {
     cout<<"g";
     datei << "Beep(396,100);"<<endl;
     datei << "Sleep(100);"<<endl;
     Beep(396,100); //g
    }
    
    if (GetAsyncKeyState(VK_h) &1 )
    {
     cout<<"a";
     datei << "Beep(440,100);"<<endl; 
     datei << "Sleep(100);"<<endl;                   
     Beep(440,100); //a
    }
    
    if (GetAsyncKeyState(VK_j) &1 )
    {
     cout<<"h";
     datei << "Beep(495,100);"<<endl;
     datei << "Sleep(100);"<<endl;
     Beep(495,100); //h
    }
    
    if (GetAsyncKeyState(VK_k) &1 )
    {
     cout<<"c";
     datei <<"Beep(598,100);"<<endl;
     datei << "Sleep(100);"<<endl;
     Beep(598,100); //c
    }
    
    ////////////////////////////
    
    if (GetAsyncKeyState(VK_F1) &1 )
    {
        system("cls");
        cout<<"Aufname = Tasten a bis k\n\n";  
        cout<<"Abspeichern = Leertaste \n\n"; 
        cout<<"Beenden = Enter-Taste\n\n";
       Sleep(10000);
       system("cls");
       main();
       break;
    }  
    
    ///////////////////////////
    if (GetAsyncKeyState(VK_SPACE) &1 )
    {
    datei << "\n}\n\nint main()\n{\nmusic();\nreturn 0;\n}\n"<<endl;
    
    datei.close();
    Sleep(1000);
    system("cls");
    cout<<"open c://music.txt and copy all in your c++ compilierer ";     
    Sleep(5000);
    system("cls");
    break;
    }
    
    }
    return 0;
    }
    

    have fun 😉 😃



  • Uahh.. schon wieder einer, der die main rekursiv aufruft.. 😮

    btw ist das nicht das Projekte Forum..



  • naja - hab mal degadcht vielleich kann damit einer was anfangen XD
    ich selber hab schon fette sachen damit gemacht

    ps: macht ein doch nicht immer sofort down wenn euch was nicht so passt wie es sein sollte :p



  • nette idee 🙂

    aber mal ganz ehrlich, das war doch sicher ne sau schriebarbeit?



  • joa - vorallen erstmal mit den , dass der in der txt datei int main und so schreibt 🤡



  • #include <fstream>
    #include <iostream>
    #include <sstream>
    #include <string>
    
    #include <windows.h>
    
    namespace tonleiter
    {
    	enum T
    	{
    		C,
    		D,
    		E,
    		F,
    		G,
    		A,
    		H,
    		C2
    	};
    }
    
    std::string GetBeepString(tonleiter::T to_play)
    {
    	int f = to_play*33+264;
    	Beep(f, 100);
    	std::stringstream ss;
    	ss << f;
    	std::string R = "Beep(" + ss.str() + ",100);";
    	R += " Sleep(100);";
    	return R;
    }
    
    bool key_pressed(int key)
    {
    	return GetAsyncKeyState(key) & 0x1;
    }
    
    int main()
    {
    	std::cout << "Patrick Ratzs C++ Music-Maker v.1.01" << std::endl
    		<< "-----------------------------------" << std::endl
    		<< "Help = F1" << std::endl;
    
    	std::fstream datei("C:/music.txt", std::ios_base::out);
    
    	datei
    		<< "#include <windows.h>" << std::endl
    		<< "void music()" << std::endl
    		<< '{';
    
    	for(bool exit(false); !exit; exit |= key_pressed(VK_RETURN))
    	{
    		if (key_pressed('A'))
    		{
    			std::cout << 'c';
    			datei << std::endl << '\t' << GetBeepString(tonleiter::C);
    		}
    
    		if (key_pressed('S'))
    		{
    			std::cout << 'd';
    			datei << std::endl << '\t' << GetBeepString(tonleiter::D);
    		}
    
    		if (key_pressed('D')) 
    		{ 
    			std::cout << 'e';
    			datei << std::endl << '\t' << GetBeepString(tonleiter::E);
    		} 
    
    		if (key_pressed('F')) 
    		{ 
    			std::cout<<"f"; 
    			datei << std::endl << '\t' << GetBeepString(tonleiter::F);
    		} 
    
    		if (key_pressed('G')) 
    		{ 
    			std::cout<<"g"; 
    			datei << std::endl << '\t' << GetBeepString(tonleiter::G);
    		} 
    
    		if (key_pressed('H')) 
    		{ 
    			std::cout<<"a"; 
    			datei << std::endl << '\t' << GetBeepString(tonleiter::A);
    		} 
    
    		if (key_pressed('J')) 
    		{ 
    			std::cout<<"h"; 
    			datei << std::endl << '\t' << GetBeepString(tonleiter::H);
    		} 
    
    		if (key_pressed('K')) 
    		{ 
    			std::cout<<"c"; 
    			datei << std::endl << '\t' << GetBeepString(tonleiter::C2);
    		} 
    
    		if (key_pressed(VK_F1)) 
    		{ 
    			system("cls");
    			std::cout << "Aufname = Tasten a bis k" << std::endl
    				<< "Abspeichern = Leertaste" << std::endl
    				<< "Beenden = Enter-Taste" << std::flush;
    			Sleep(7000); 
    			system("cls"); 
    		}   
    
    		if (key_pressed(VK_SPACE)) 
    		{
    			datei << std::endl
    				<< '}' << std::endl
    				<< std::endl
    				<< "int main()" << std::endl
    				<< '{' << std::endl
    				<< "\tmusic();" << std::endl
    				<< '}' << std::endl;
    
    			Sleep(1000);
    			system("cls");
    			std::cout << "open \'c:/music.txt\' and copy all in your c++ compilierer";
    			Sleep(5000);
    			system("cls");
    			exit = true;
    		}
    	}
    }
    

    btw: was muss man tun, um unter Vista auch Beep's zu hören? ><
    bb



  • Skym0sh0 schrieb:

    aber mal ganz ehrlich, das war doch sicher ne sau schriebarbeit?

    Soll das ein Scherz sein ?
    die paar Zeilen sind doch nix.

    EDIT: Aber die Idee ist super geil fällt mir grad auf, das macht sogar voll fun ^^



  • Tim06TR schrieb:

    Skym0sh0 schrieb:

    aber mal ganz ehrlich, das war doch sicher ne sau schriebarbeit?

    Soll das ein Scherz sein ?
    die paar Zeilen sind doch nix.

    Naja, wenn man weiß was Arrays und Schleifen sind bekommt man es auch mit ca. 10% des Codes hin, also wars ne sau schriebarbeit.



  • warum wird innerhalb des codes eigtl : D zu 😃 ersetzt? so was dummes 😣

    bb


Anmelden zum Antworten