-1

Hi I am trying to count in note data from keyboard and write the data to a text file which will subsequently be read out of and played back as notes.

I seem to only be able to write one line of numbers to the text file and help would be most appreciated. Sorry i still have some of my function code included in the global.

    #define SEQ_NOTENUM 8
    #define SEQ_NUM 2
    //  structures //

    typedef struct
    {
         int notenumber;
         int velocity;
    }NoteData;

    typedef struct
    {
        float frequency;
        float amplitude;
    } OscData;

    // functions //

     float mtof(int note);


    // originally in main //

    OscData noteToOsc(NoteData note);
    int setcount, count;
    int currentset;
    OscData osc;

    int main()

    {
        int key, vel;
        NoteData sequence[SEQ_NUM][SEQ_NOTENUM];
        OscData noteToOsc(NoteData note);
        FILE* Sequence1;

        // START PROGRAM RECORD -- WRITE an IF/ELSE to run program -   
      dummy line atm//
        aserveGetVelocity();


        Sequence1 = fopen ("sequence1.txt", "w");

        if (Sequence1 == NULL)

         {
             printf("file Error\n");
         }

         else
          {
                    for(setcount = 0; setcount < SEQ_NUM; setcount++)
             {
                printf("--- Please enter sequence %d (%d notes)...\n",
    setcount, SEQ_NUM);



                count = 0;

                while(count < SEQ_NOTENUM)
                 {
                      key = aserveGetNote();
                      vel = aserveGetVelocity();

                    if(vel > 0)
                     {
                         sequence[setcount][count].notenumber = key;
                         sequence[setcount][count].velocity = vel;

                fprintf(Sequence1, "note %d - %d/%d\n", count, key,
     vel);
                count++;

            }

            fclose(Sequence1);
        }

        return 0;
    }

    }
Servy
  • 202,030
  • 26
  • 332
  • 449
  • What language is this written in? Without a proper tag it's unlikely you'll get an answer – Machavity Mar 23 '15 at 20:26
  • sorry i thought i did.. oops. It's in C and just added the tags – Mikey O'Keefe Mar 23 '15 at 20:29
  • Have you tried temporarily replacing `fprintf` with `printf` (i.e., redirecting the output to stdout instead of the file), to check if the issue might be something other than the file output? – Brent Kerby Mar 23 '15 at 20:33
  • @BrentKerby I have tried that and there seems to be no issue. It prints out 2x 8 note numbers and velocity numbers with no issues, any other ideas it's driving me crazy haha? – Mikey O'Keefe Mar 23 '15 at 22:25

1 Answers1

0

The code's indentation is messed up, obscuring the fact that fclose(Sequence1) is closing the file after only one pass through the inner loop. You probably want to move that to somewhere further down.

Brent Kerby
  • 1,397
  • 8
  • 14