Exemplo n.º 1
0
int main()
{
#ifdef __MIPSEL__
    create_app_dir(BASE_PATH);
#endif

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        log(FATAL, "Cannot init SDL.");
    }

    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF)))
    {
        SDL_Quit();
        log(FATAL, "Cannot SetVideoMode.");
    }

    SDL_ShowCursor(SDL_DISABLE);

    if (TTF_Init() < 0)
    {
        SDL_Quit();
        log(FATAL, "Unable to start the TTF.");
    }

    int img_flags = IMG_INIT_PNG;

    if(!(IMG_Init(img_flags) & img_flags))
    {
        TTF_Quit();
        SDL_Quit();
        log(FATAL, "SDL_image could not initialize. %s.", IMG_GetError());
    }

    pconfig = new Config();
    pconfig->load();

    pmixer = new Mixer();
    current_volume = pmixer->get_speaker_volume();
    pmixer->set_speaker_volume(current_volume);

    load_resources();
    draw_buttons();
    draw_timer(0, 0, 0);
    draw_volume();
    draw_vu(1, -1);
    draw_vu(1, 1);

    pmic = new Mic();
    pmic->set_on_terminate_event(on_terminate_exec);
    pmic->set_on_vu_change_event(on_vu_changed);

    main_loop();

    delete pmic;
    delete pmixer;
    delete pconfig;

    TTF_CloseFont(font_10);
    TTF_CloseFont(font_28);

    IMG_Quit();
    TTF_Quit();
    SDL_Quit();

    return 0;
}
Exemplo n.º 2
0
static void mp3_refresh_state()
{
	dsp_vol_change(&dspz, vol_delta);
	rect_wait = RECT_CYCLES;
	draw_volume();
}
Exemplo n.º 3
0
void main_loop()
{
    SDL_Event event;
    bool quit = false;

    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

    while(!quit && SDL_WaitEvent(&event))
    {
        switch(event.type)
        {
            case SDL_KEYDOWN:
            //case SDL_KEYUP:
            {
                SDLKey key = event.key.keysym.sym;
                switch (key)
                {
                    case SELECT_BUTTON:
                        quit = true;
                    break;
                    case A_BUTTON:
                        if (is_playing) continue;

                        if (is_recording)
                        {
                            pmic->stop();
                        }
                        else
                        {
                            current_file = pconfig->get_new_file_name();
                            pmixer->set_direction(CAPTURE);
                            pmic->capture(current_file,
                                          pconfig->get_file_type(),
                                          pconfig->get_file_format(),
                                          pconfig->get_channel(),
                                          pconfig->get_rate(),
                                          0);
                        }

                        is_recording = !is_recording;
                        draw_buttons();
                    break;
                    case B_BUTTON:
                        if (is_recording || current_file.empty()) continue;

                        if (is_playing)
                        {
                            pmic->stop();
                        }
                        else
                        {
                            pmixer->set_direction(PLAYBACK);
                            pmic->play(current_file);
                        }

                        is_playing = !is_playing;
                        draw_buttons();
                    break;
                    case UP_BUTTON:
                        if (current_volume < 100)
                        {
                            current_volume++;
                            draw_volume();
                            pmixer->set_speaker_volume(current_volume);
                            log(INFO, "Volume changed to %ld.", current_volume);
                        }
                    break;
                    case DOWN_BUTTON:
                        if (current_volume > 0)
                        {
                            current_volume--;
                            draw_volume();
                            pmixer->set_speaker_volume(current_volume);
                            log(INFO, "Volume changed to %ld.", current_volume);
                        }
                    break;
                    default:
                        log(INFO, "Invalid key.");
                    break;
                }
            }
            break;
            case SDL_QUIT: /* window close */
                quit = true;
            break;
            default:
                //log(INFO, "Invalid key.");
            break;
        }
    }
}