bandData openFile(string presetName) {
    ifstream                preset;
    string                  line;
    int                     num_bands, num_channels,
                            row, col, k, ind;
    int                     response;
    bandData                band;

    scrollok(stdscr, FALSE);

    band.maxidx = 0;

    // Get preset filename and open
    while(!preset.is_open()) {
        erase();
        printw("Preset filename: %s\n",presetName.c_str());
        refresh();
        preset.open(presetName.c_str());
    }

    // Display contents and close
    if (preset.is_open()) {
        vector<int>     int_channels;
        while ( getline (preset,line) ) {
            if ( line == "INTENSITY_CHANNELS") {
                //int_channels line
                printw("%s\n",line.c_str());
                while ( getline(preset,line) && line != "BAND1" ) {
                    int_channels.push_back(atoi(line.c_str()));
                    printw("%s\n",line.c_str());
                }
            }
            if ( line == "NUM_BANDS" ) {
                printw("%s\n",line.c_str());
                getyx(stdscr,row,col);
                chkend(row);
                getline(preset,line);
                printw("%s\n",line.c_str());
                getyx(stdscr,row,col);
                chkend(row);
                num_bands = atoi(line.c_str());
                getline(preset,line);
                printw("%s\n",line.c_str());
                getyx(stdscr,row,col);
                chkend(row);
                getline(preset,line);
                num_channels = atoi(line.c_str());
                getyx(stdscr,row,col);
                chkend(row);
            }
            printw("%s\n",line.c_str());
            getyx(stdscr,row,col);
            chkend(row);
        }

        band.int_channels = new int[int_channels.size()];
        for (k=0; k<int_channels.size(); k++) {
            band.int_channels[k] = int_channels[k]-1;
        }
        band.num_int_channels = int_channels.size();

    } else {
        printw("Unable to open file.\n");
        return band;
    }
    refresh();
    preset.close();
    getyx(stdscr,row,col);
    chkend(row);
    printw("\n\nPress %s to load this preset.", SELECT_STR);
    refresh();
    response = getch();
    if ( response != SELECT ) {
        printw("\nReturning to main menu.\n");
        refresh();
        sleep(2);
        return band;
    }


    /*
        band.idx = 0;
        band.maxidx = num_bands;
        band.lind = (int*) malloc( (num_bands - 1) * sizeof(int) );
        band.hind = (int*) malloc( (num_bands - 1) * sizeof(int) );
        band.dmx_size = (int*) malloc( num_bands * sizeof(int) );
        band.dmx = (int**) malloc( (num_bands - 1) * sizeof(int*) );
        band.avg = (double*) malloc( (num_bands - 1) * sizeof(double) );
        band.gain = (float*) malloc( (num_bands - 1) * sizeof(float) );
        band.int_channels = (int*) malloc( int_channels.size() * sizeof(int) );
        for (k=0; k<int_channels.size(); k++) {
            band.int_channels[k] = int_channels[k]-1;
        }
        k = 1;
        band.num_int_channels = int_channels.size();
    */

    k = 1;
    band.idx = 0;
    band.maxidx = num_bands;
    band.lind = new int[num_bands-1];
    band.hind = new int[num_bands-1];
    band.dmx_size = new int[num_bands];
    band.dmx = new int*[num_bands-1];
    for (int i=0; i<num_bands; i++ ) {
        //      band.dmx[i] = new int[10];
    }
    band.avg = new float[num_bands-1];
    band.gain = new float[num_bands-1];
    preset.open(presetName.c_str());
    printw("\nLoading preset. . . \n");
    refresh();

    if ( preset.is_open() ) {
        stringstream    ss;
        string          bandline = "BAND";
        vector<int>             temp;
        int             i, n, pos;
        float           skip;
        int lind, hind;
        skip = SAMPLE_RATE / 2;
        skip = skip / ( (FRAMES_PER_BUFFER + INPUT_PADDING)/2 - 1 );
        while ( k <= num_bands && getline(preset,line)) {
            i = 0;
            bandline = "BAND";
            ss.str(std::string());
            ss << k;
            bandline += ss.str();
            getyx(stdscr,row,col);
            chkend(row);
            if ( line == bandline ) {
                printw("Retrieving band %i. . .\n",k);
                refresh();
                usleep(55000);
                getline(preset,line);
                lind = round( atoi(line.c_str()) / skip );
                band.lind[k-1] = round( atoi(line.c_str()) / skip );
                getline(preset,line);
                band.hind[k-1] = round( atoi(line.c_str()) / skip );
                hind = round( atoi(line.c_str()) / skip );
                printw("Getting DMX channels for band %i\n",k);
                refresh();
                usleep(55000);
                ss.str(std::string());
                bandline = "BAND";
                ss << k+1;
                bandline += ss.str();
                getyx(stdscr,row,col);
                chkend(row);
                getline(preset,line);
                char    temparray[4];
                while( getline(preset,line) && ( line != bandline ) ) {
                    pos = preset.tellg();
                    if ( line[0] == 'G' ) {
                        for (ind=1; ind<=line.length(); ind++) {
                            temparray[ind-1] = line[ind];
                        }
                    }
                    temp.push_back(atoi(line.c_str()));
                    i++;
                }
                i--;
                preset.seekg(pos);
                printw("Retrieved %i channels. . .\n",i);
                refresh();
                usleep(55000);
                band.gain[k-1] = 1 + atof(temparray) / GAIN_SCALE;
                band.dmx[k-1] = new int[i];
                for (n=0; n<i; n++) {
                    band.dmx[k-1][n] = temp[n]-1;
                }
                band.dmx_size[k-1] = i;
                temp.clear();
                //i=0;
                k++;
            }
        }
        preset.close();
    } else {
        printw("Error loading preset.\n");
    }
    printw("Preset loaded.\n");
    scrollok(stdscr, TRUE);
    refresh();

    return band;

}
Esempio n. 2
0
File: syntax.c Progetto: E-LLP/VICAR
    FUNCTION main ()

    {
    struct SYNBLK	sb;		/* syntax block				*/
    TEXT		s[STRINGSIZ+1];	/* string buffer			*/
    TEXT		verb[TOKESIZ+1];/* verb					*/
    TEXT		key[TOKESIZ+1];	/* keyword				*/
    TEXT		*value[MAXVAL];	/* value pointers			*/
    CODE		code;
    COUNT		count;
    COUNT		tstnum;
    COUNT		i;
    CODE		dum;

    dumrout(&code, &tstnum);		/* dummy - get addrs w/ debugger	*/

    tstnum = 0;

/* TEST 1 */
    printf("\n TEST 1 \n");
    s_copy("menu file=alpha a", s);
    initok(&sb, s);
    tstnum++;

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);
    tstnum++;

    code = getkey(&sb, key);
    printf(" code: %d, key: %s\n", code, key);
    tstnum++;

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);
    tstnum++;

    code = chkend(&sb);
    tstnum++;

/* TEST 2 */
    printf("\n TEST 2 \n");
    s_copy("menu (A, B, CDE) file = alpha", s);
    initok(&sb, s);

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getkey(&sb, key);
    printf(" code: %d, key: %s\n", code, key);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = chkend(&sb);

/* TEST 3 */
    printf("\n TEST 3 \n");
    s_copy("vrb ,(A,,C,) f,", s);
    initok(&sb, s);

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

/* TEST 4 */
    printf("\n TEST 4 \n");
    s_copy("(\"aaa\", \"bbb\")", s);
    initok(&sb, s);


    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);


/* TEST 5 */
    printf("\n TEST 5 \n");	/* white space test		*/
    s_copy("menu (A, B, CDE) file = alpha", s);
    initok(&sb, s);

    code = getvrb(&sb, verb);
    printf(" code: %d, verb: %s\n", code, verb);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = getkey(&sb, key);
    printf(" code: %d, key: %s\n", code, key);

    code = getval(&sb, value, MAXVAL, &count);
    printf(" code: %d, count: %d, values:  \n", code, count);
    for (i=0; i<count; i++)
	printf("    %s\n", value[i]);

    code = chkend(&sb);


/* USER TEST */
    while (FOREVER)
	{

	printf("\n Enter a string of values:\n");
	t_init(&dum, &dum, &dum);
	t_read(s, &dum);
	initok(&sb, s);


	code = getval(&sb, value, MAXVAL, &count);
	while (code !=EOS && code!=S_SYNERR)
	    {
	    printf(" code: %d, count: %d, values:  \n", code, count);
	    for (i=0; i<count; i++)
		printf("    %s\n", value[i]);
	    code = getval(&sb, value, MAXVAL, &count);
	    }	
	}

    sb.errchr = sb.curchr - 1;
    synerr(&sb, "Test complete");

    exit(TRUE);
    }