Exemplo n.º 1
0
/**
 * @brief Detect the format of message stored in a buffer.
 * Determine the message format used in a stream of bytes.
 * @public @memberof MIDIMessageFormat
 * @param buffer The message as it would appear on a MIDI cable.
 * @return a pointer to the correct message format if the format could be detected.
 * @return a NULL pointer if the format could not be detected.
 */
struct MIDIMessageFormat * MIDIMessageFormatDetect( void * buffer ) {
  static struct MIDIMessageFormat * formats[] = {
    &_note_off_on,
    &_polyphonic_key_pressure,
    &_control_change,
    &_program_change,
    &_channel_pressure,
    &_pitch_wheel_change,
    &_system_exclusive,
    &_time_code_quarter_frame,
    &_song_position_pointer,
    &_song_select,
    &_tune_request,
    &_real_time
  };
  int i;
  MIDIPrecondReturn( buffer != NULL, EFAULT, NULL );
  for( i=0; i<N_ELEM(formats); i++ ) {
    MIDIAssert( formats[i] != NULL && formats[i]->test != NULL );
    if( (formats[i]->test)( buffer ) ) {
      return formats[i];
    }
  }
  return NULL;
}
Exemplo n.º 2
0
void log_open( log_t* log, const char* name ) {
    static struct {
        const char* name;
        int fd;
    } special[] = {
        { "stdout", 1 },
        { "-", 1 },
        { "stderr", 2 }
    };
    int i, fd = -1;

    term_t term;

    log->file = NULL;
    log->isatty = false;

    term.lines = 1;
    term.columns = 132;
    term.colors = 2;
    term.unicode = true;

    for( i=0; i<N_ELEM(special); i++ ) {
        if( strcmp(special[i].name, name) == 0 ) {
            fd = special[i].fd;
            break;
        }
    }
    if( fd == -1 ) {
        fd = open(name, O_WRONLY);
    }
    if( fd >= 0 ) {
        log->file   = fdopen(fd, "w+");
        log->isatty = isatty(fd);
    }
    if( log->isatty && termcap( &term ) == 0 ) {
        log->lines   = term.lines;
        log->columns = term.columns;
        log->colors  = term.colors;
        log->unicode = term.unicode;
    }
    log_fmt( log, "colors: %hi, lines: %hi, columns: %i\n", log->colors, log->lines, log->columns );
}
Exemplo n.º 3
0
void Environment::addWalls(void)
{
    Point3 p_xyz = Point3(-extent_/2, -extent_/2, -extent_/2);
    Point3 p_xyZ = Point3(-extent_/2, -extent_/2,  extent_/2);
    Point3 p_xYz = Point3(-extent_/2,  extent_/2, -extent_/2);
    Point3 p_xYZ = Point3(-extent_/2,  extent_/2,  extent_/2);
    Point3 p_Xyz = Point3( extent_/2, -extent_/2, -extent_/2);
    Point3 p_XyZ = Point3( extent_/2, -extent_/2,  extent_/2);
    Point3 p_XYz = Point3( extent_/2,  extent_/2, -extent_/2);
    Point3 p_XYZ = Point3( extent_/2,  extent_/2,  extent_/2);

    struct WallSpec {
        Point3 pLL, pLR, pUL;

        // row and column of subimage within 3 x 4 subdivision
        int iFace, jFace;
    } wallSpecs[] = {
        { p_xyz, p_xYz, p_xyZ, 1, 3 }, // back
        { p_XYz, p_Xyz, p_XYZ, 1, 1 }, // front
        { p_xYz, p_XYz, p_xYZ, 1, 0 }, // left
        { p_Xyz, p_xyz, p_XyZ, 1, 2 }, // right
        { p_XYZ, p_XyZ, p_xYZ, 2, 1 }, // top
#if 0 // if needed (bottom is filled by Ground)
        { p_xYz, p_xyz, p_XYz, 0, 0 }, // bottom
#endif
    };

    for (unsigned int i = 0; i < N_ELEM(wallSpecs); i++) {
        const Image *wallImage = skymapImage->getSkymapFaceImage(
            wallSpecs[i].iFace, wallSpecs[i].jFace);
        Wall *wall = new Wall(wallImage,
                wallSpecs[i].pLL, wallSpecs[i].pLR, wallSpecs[i].pUL,
                2, 2, texturedShaderProgram);
        walls.push_back(wall);
        // TBD: delete "wallImage"
    }
    // TBD: delete "image"
}
Exemplo n.º 4
0
int
main()
{
    initLexer(0);

    testTokenStream("1 + 1", tokens0, N_ELEM(tokens0));
    testTokenStream("{a comment line} $1 + 1", tokens0, N_ELEM(tokens0));
    testTokenStream("{{a nested comment}} $1 + 1", tokens0, N_ELEM(tokens0));
    testTokenStream("{{{a nested doc comment}} $1 + 1", tokens0, N_ELEM(tokens0));
    testTokenStream("x-1+y", tokens1, N_ELEM(tokens1));
    testTokenStream("_x0{some comment 1} - 1 + y_99", tokens1, N_ELEM(tokens1));
    testTokenStream("con CON con99 Con 99", tokens2, N_ELEM(tokens2));
    testTokenStream("< =< => > == = +<", tokens3, N_ELEM(tokens3));
    testTokenStream(token4test, tokens4, N_ELEM(tokens4));
    testTokenStream(token5test, tokens5, N_ELEM(tokens5));
    testTokenStream(token6test, tokens6, N_ELEM(tokens6));
    testTokenStream(token7test, tokens7, N_ELEM(tokens7));

    testNumber("0", 0);
    testNumber("00", 0);
    testNumber("007", 7);
    testNumber("008", 8);
    testNumber("\t \t 123", 123);
    testNumber("65535", 65535);
    testNumber("  $41", 65);
    testNumber("$01_ff", 511);
    testNumber("$A5", 165);
    testNumber("%101", 5);
    testNumber("%11", 3);
    testNumber("%%31", 13);
    testNumber("80_000_000", 80000000);

    testFloat("1.0", 1.0f);
    testFloat("2.0", 2.0f);
    testFloat("0.01", 0.01f);
    testFloat("1.0e-2", 0.01f);
    testFloat("1.e-2", 0.01f);
    testFloat("3.14e5", 314000.0f);

    testIdentifier("x99+8", "X99");
    testIdentifier("_a_b", "_A_b");
    printf("all tests passed\n");
    return 0;
}