POP Doc Retour vers le futur

Passer en version ordinateur
Vous connaissez un site pour acheter des hoverboards à moitié prix ? Partagez le ici...
⮕⮕⮕ EN COURS : archivage du forum ici https://www.youtube.com/@retourverslefutur.com-archive
Sujet verrouillé

compiler C

02 Oct 2010, 21:01

Code:
/**
 * file                       : main.cpp
 *------------------------------------------
 * Author                     : Christophe Angeli
 * Improvements & portability : Arnaud Calmettes
 *
 */
#include <cstdlib>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>

#ifndef __unix__
# include <windows.h>
#endif


// Note/Octave/Frequency matching

int NOTES[12][9] =
{
    {16, 33, 65, 131, 262, 523, 1046, 2093, 4186},
    {17, 35, 69, 139, 277, 554, 1109, 2217, 4435},
    {18, 37, 73, 147, 294, 587, 1175, 2349, 4699},
    {19, 39, 78, 155, 311, 622, 1244, 2489, 4978},
    {21, 41, 82, 165, 330, 659, 1328, 2637, 5274},
    {22, 44, 87, 175, 349, 698, 1397, 2794, 5588},
    {23, 46, 92, 185, 370, 740, 1480, 2960, 5920},
    {24, 49, 98, 196, 392, 784, 1568, 3136, 6271},
    {26, 52, 104, 208, 415, 831, 1661, 3322, 6645},
    {27, 55, 110, 220, 440, 880, 1760, 3520, 7040},
    {29, 58, 116, 233, 466, 932, 1865, 3729, 7459},
    {31, 62, 123, 245, 494, 988, 1975, 3951, 7902}
};

enum
{
    SILENCE = -1,
    DO = 0,
    DO_ = 1,
    RE = 2,
    RE_ = 3,
    MI = 4,
    FA = 5,
    FA_ = 6,
    SOL = 7,
    SOL_ = 8,
    LA = 9,
    LA_ = 10,
    SI = 11
};

enum
{
    OCTAVE_0 = 0,
    OCTAVE_1 = 1,
    OCTAVE_2 = 2,
    OCTAVE_3 = 3,
    OCTAVE_4 = 4,
    OCTAVE_5 = 5,
    OCTAVE_6 = 6,
    OCTAVE_7 = 7,
    OCTAVE_8 = 8,
};

std::map<std::string, int> noteMap;

// Global variables
int TEMPO = 250;
int DURATION=TEMPO;
int OCTAVE = 0;

#ifdef __unix__
/**
 * Linux (dirty) adaptation from <windows.h>'s Beep function
 */
void Beep(int freq, int length)
{
    std::stringstream ossBeep;
    ossBeep << "beep -f " << freq << " -l " << length;
    system(ossBeep.str().c_str());
}
#endif


/**
 * Reads the music sheet
 */
int readFile( const char *file )
{
    std::ifstream musicFile(file);
    if (! musicFile.is_open() )
        return 1;
   
    int octave = 0;
    double duration = 0;   
    std::string duration_str;   
    std::string line;
    std::string note;
   
   
    while ( std::getline( musicFile, line ) )
    {
        note = "";
        octave = 0;
        duration = 0;
        duration_str = "";

        std::stringstream lineStream(line);
        lineStream >> note >> octave >> duration_str;
       
        // Empty line skipping
        if( note == "" )
            continue;

        // Tempo management
        std::string::size_type pos = note.find("TEMPO");
        if( pos  != std::string::npos )
    {
            if( octave != 0)
            {           
                TEMPO = octave;
                DURATION = TEMPO;
                continue;
            }
        }
   
        // Octave management   
        if( octave )
        {
            OCTAVE = octave;
    }

        // Duration management
        // (this looks dirty because of fraction interpretation)
        if( duration_str != "" )
        {
            pos = duration_str.find('/');
            if( pos != std::string::npos)
            {
                std::istringstream numerateur( duration_str.substr(0,pos+1) );
                std::istringstream denominateur (duration_str.substr(pos+1, duration_str.size()-(pos + 1)) );
                int num = 1;
                int den = 1;
                numerateur >> num;
                denominateur >> den;
                DURATION = (int) (TEMPO * num / den);
            }
            else
            {
                std::istringstream stream(duration_str);
                stream >> duration;
                DURATION = (int) (TEMPO * duration);
            }
        }

        // Silence management
        if (noteMap[note.c_str()] == SILENCE)
            Beep(1, DURATION);
        else
            // Finally, play the note !
            // This calls the "Beep" system function under windows
            // Or the custom one under Linux
            Beep(NOTES[ noteMap[note.c_str()] ][ OCTAVE ], DURATION);
    }
    return 0;
}


// Main : Basic declarations and parameter parsing
int main(int argc, char* argv[])
{
    noteMap["DO"] = DO;
    noteMap["DO_"] = DO_;
    noteMap["RE"] = RE;
    noteMap["RE_"] = RE_;
    noteMap["MI"] = MI;
    noteMap["FA"] = FA;
    noteMap["FA_"] = FA_;
    noteMap["SOL"] = SOL;
    noteMap["SOL_"] = SOL_;
    noteMap["LA"] = LA;
    noteMap["LA_"] = LA_;
    noteMap["SI"] = SI;
    noteMap["_"] = SILENCE;


    if( argc == 0 || ( argc != 0 && readFile(argv[1]) == 1 ))
        std::cout << "Usage : " << argv[0] << " FILENAME \n" << std::endl;

    return 0;
}

Quelqu'un pourrai t'il me compiler ce code SVP ?

06 Oct 2010, 19:07

Je peux te le compiler si tu veux
Dernière édition par gab le 06 Oct 2010, 19:26, édité 1 fois.

06 Oct 2010, 19:08

je veux bien. Merci

06 Oct 2010, 19:14

A propos en quoi je te le compile? je programme avec code bloc et je suis débutant

07 Oct 2010, 17:09

avec ça !

08 Oct 2010, 12:36

Mais je pense que c'est déjà compilé non? parce que la compilation c'est la traduction de ton programment en binaire (0.1.1et etc) non?

08 Oct 2010, 16:31

C'est pas compilé. Il est en langage 'humain' et non en binaire.

08 Oct 2010, 16:41

Ah ok je vois ce que tu veux dire mais tu peux pas le faire avec le logiciel? normalement code bloc le permet enfin moi ça me dérange pas de te le compiler :a38: enfin bref pourquoi tu peux pas le compiler?

08 Oct 2010, 17:14

L'installation ne marche pas chez moi !

08 Oct 2010, 18:52

Ah ok je vais faire la compilation de ton programme

08 Oct 2010, 18:57

Merci !
Voici le lien ou j'ai trouver le code-source, si ca peut t'aider :
http://www.siteduzero.com/forum-83-3506 ... re-pc.html

08 Oct 2010, 19:01

Merci pour le lien et j'ai compilé ton programme en C (j'ai fait au hasard étand donné que je ne savais pas en quoi il est programmé donc le l'ai mis en C mais je sais pas si ça te convient) et je t'envoi le fichier?

08 Oct 2010, 19:55

oui, merci ! ( par MP par ex !)

09 Oct 2010, 10:31

ok je vais te l'envoyer :a38:

09 Oct 2010, 10:41

Merci !!!!

09 Oct 2010, 13:48

Heu.. j'ai un ptit problème comment on envoie un fichier?

09 Oct 2010, 17:36

avec :
http://dl.free.fr/

09 Oct 2010, 17:37

Ok merci!!

09 Oct 2010, 17:55

de rien !

09 Oct 2010, 21:09

Et voici le lien:http://dl.free.fr/clTBQjwbu par contre le dossier est compréssé (winrar) et heu je crois avoir fait une faute d'orthographe de ton pseudo

10 Oct 2010, 15:30

C'est pas grave. Merci !
Sujet verrouillé

 

Lego Retour vers le futur


 

The end


 

POP Marty Retour vers le futur


 

Playmobil Retour vers le futur

Retourverslefutur.com participe au Programme Partenaires d’Amazon EU, un programme d’affiliation publicitaire conçu pour permettre à des sites de percevoir une rémunération grâce à la création de liens vers Amazon.fr.