예제 #1
0
static bool _ogl_is_extension_with_version_supported(
    const char *extension, ALLEGRO_DISPLAY *disp, uint32_t ver)
{
    ALLEGRO_CONFIG *cfg;
    char const *value;

    /* For testing purposes, any OpenGL extension can be disable in
      * the config by using something like:
      *
      * [opengl_disabled_extensions]
      * GL_ARB_texture_non_power_of_two=0
      * GL_EXT_framebuffer_object=0
      *
      */
    cfg = al_get_system_config();
    if (cfg) {
        value = al_get_config_value(cfg,
                                    "opengl_disabled_extensions", extension);
        if (value) {
            ALLEGRO_WARN("%s found in [opengl_disabled_extensions].\n",
                         extension);
            return false;
        }
    }

    /* If the extension is included in the OpenGL version, there is no
     * need to check the extensions list.
     */
    if (ver > 0 && disp->ogl_extras->ogl_info.version >= ver) {
        return true;
    }

    return _ogl_is_extension_supported(extension, disp);
}
예제 #2
0
파일: audio.c 프로젝트: allefant/allegro
static ALLEGRO_AUDIO_DRIVER_ENUM get_config_audio_driver(void)
{
    ALLEGRO_CONFIG *config = al_get_system_config();
    const char *value;

    if (!config)
        return ALLEGRO_AUDIO_DRIVER_AUTODETECT;

    value = al_get_config_value(config, "audio", "driver");
    if (!value || value[0] == '\0')
        return ALLEGRO_AUDIO_DRIVER_AUTODETECT;

    if (0 == _al_stricmp(value, "ALSA"))
        return ALLEGRO_AUDIO_DRIVER_ALSA;

    if (0 == _al_stricmp(value, "OPENAL"))
        return ALLEGRO_AUDIO_DRIVER_OPENAL;

    if (0 == _al_stricmp(value, "OPENSL"))
        return ALLEGRO_AUDIO_DRIVER_OPENSL;

    if (0 == _al_stricmp(value, "OSS"))
        return ALLEGRO_AUDIO_DRIVER_OSS;

    if (0 == _al_stricmp(value, "PULSEAUDIO"))
        return ALLEGRO_AUDIO_DRIVER_PULSEAUDIO;

    if (0 == _al_stricmp(value, "DSOUND") || 0 == _al_stricmp(value, "DIRECTSOUND"))
        return ALLEGRO_AUDIO_DRIVER_DSOUND;

    return ALLEGRO_AUDIO_DRIVER_AUTODETECT;
}
예제 #3
0
static ALLEGRO_DISPLAY_INTERFACE *xglx_get_display_driver(void)
{
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();

   /* Look up the toggle_mouse_grab_key binding.  This isn't such a great place
    * to do it, but the config file is not available until after the system driver
    * is initialised.
    */
   if (!system->toggle_mouse_grab_keycode) {
      const char *binding = al_get_config_value(al_get_system_config(),
         "keyboard", "toggle_mouse_grab_key");
      if (binding) {
         system->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
            &system->toggle_mouse_grab_modifiers);
         if (system->toggle_mouse_grab_keycode) {
            ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
         }
         else {
            ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
         }
      }
   }

   return _al_display_xglx_driver();
}
예제 #4
0
/* Checks whether the configured joystick driver is of the given name.
 * Also returns false if the configuration entry was not set.
 */
static bool win_configured_joystick_driver_is(const char * name)
{
    const char * driver;
    ALLEGRO_CONFIG * sysconf = al_get_system_config();
    if (!sysconf) return false;
    driver = al_get_config_value(sysconf, "joystick", "driver");
    if (!driver) return false;
    ALLEGRO_DEBUG("Configuration value joystick.driver = %s\n", driver);
    return (0 == _al_stricmp(driver, name));
}
예제 #5
0
static void dsound_set_buffer_size(int bits_per_sample)
{
   int buffer_size_in_samples = 8192; // default
   const char *val = al_get_config_value(al_get_system_config(),
      "directsound", "buffer_size");
   if (val && val[0] != '\0') {
      int n = atoi(val);
      if (n < MIN_BUFFER_SIZE)
         n = MIN_BUFFER_SIZE;
      buffer_size_in_samples = n;
   }

   buffer_size = buffer_size_in_samples * (bits_per_sample/8);
}
예제 #6
0
static HWND get_window()
{
   const char *val = al_get_config_value(al_get_system_config(),
      "directsound", "window");
   HWND ret;
   if (val && strncmp(val, "foreground", 10) == 0) {
      ret = GetForegroundWindow();
      ALLEGRO_INFO("Using foreground window: %p\n", ret);
   }
   else {
      ret = GetDesktopWindow();
      ALLEGRO_INFO("Using desktop window: %p\n", ret);
   }
   return ret;
}
static void dsound_set_buffer_size(int bits_per_sample)
{
   ALLEGRO_CONFIG *config = al_get_system_config();

   if (config) {
      const char *val = al_get_config_value(config,
         "directsound", "buffer_size");
      if (val && val[0] != '\0') {
         int n = atoi(val);
         if (n < MIN_BUFFER_SIZE)
            n = MIN_BUFFER_SIZE;
         buffer_size_in_samples = n;
      }
   }

   buffer_size = buffer_size_in_samples * (bits_per_sample/8);
}
예제 #8
0
static bool ljoy_detect_device_name(int num, ALLEGRO_USTR *device_name)
{
    char key[80];
    const char *value;
    struct stat stbuf;

    al_ustr_truncate(device_name, 0);

    snprintf(key, sizeof(key), "device%d", num);
    value = al_get_config_value(al_get_system_config(), "joystick", key);
    if (value)
        al_ustr_assign_cstr(device_name, value);

    if (al_ustr_size(device_name) == 0)
        al_ustr_appendf(device_name, "/dev/input/event%d", num);

    return (stat(al_cstr(device_name), &stbuf) == 0);
}
예제 #9
0
/* Reads version info out of glGetString(GL_VERSION) */
static uint32_t _al_ogl_version(void)
{
#if !defined ALLEGRO_IPHONE && !defined ALLEGRO_ANDROID
    ALLEGRO_CONFIG *cfg;
    const char *str;

    cfg = al_get_system_config();
    if (cfg) {
        char const *value = al_get_config_value(cfg,
                                                "opengl", "force_opengl_version");
        if (value) {
            uint32_t v = parse_opengl_version(value);
            ALLEGRO_INFO("OpenGL version forced to %d.%d.%d.%d.\n",
                         (v >> 24) & 0xff,
                         (v >> 16) & 0xff,
                         (v >> 8) & 0xff,
                         (v & 0xff));
            return v;
        }
    }

    str = (const char *)glGetString(GL_VERSION);
    if (str) {
        return parse_opengl_version(str);
    }
    else {
        /* The OpenGL driver does not return a version
         * number. However it probably supports at least OpenGL 1.0
         */
        return _ALLEGRO_OPENGL_VERSION_1_0;
    }
#else
    /* XXX this is asking for trouble, and should be documented */
    const char *s = (char *)glGetString(GL_VERSION);
    if (strstr(s, "2.0"))
        return _ALLEGRO_OPENGL_VERSION_2_0;
    else if (strstr(s, "1.1"))
        return _ALLEGRO_OPENGL_VERSION_1_1;
    else
        return _ALLEGRO_OPENGL_VERSION_0;
#endif
}
예제 #10
0
파일: oss.c 프로젝트: sesc4mt/mvcdecoder
static int oss_open_ver3(void)
{
   ALLEGRO_CONFIG *config = al_get_system_config();
   if (config) {
      const char *config_device;
      config_device = al_get_config_value(config, "oss", "device");
      if (config_device && config_device[0] != '\0')
         oss_audio_device_ver3 = config_device;
   }

   int fd = open(oss_audio_device_ver3, O_WRONLY);
   if (fd == -1) {
      switch (errno) {
         case ENXIO:
         case ENODEV:
            ALLEGRO_ERROR("Open Sound System is not running in your "
                          "system.\n");
         break;

         case ENOENT:
            ALLEGRO_ERROR("No '%s' device available in your system.\n",
               oss_audio_device_ver3);
            ALLEGRO_ERROR("Perhaps Open Sound System is not installed "
                          "or running.\n");
         break;

         default:
            ALLEGRO_ERROR("errno: %i -- %s\n", errno, strerror(errno));
      }

      return 1;
   }

   close(fd);
   strncpy(oss_audio_device, oss_audio_device_ver3, 512);
   ALLEGRO_INFO("Using device: %s\n", oss_audio_device);

   using_ver_4 = false;

   return 0;
}
예제 #11
0
파일: oss.c 프로젝트: sesc4mt/mvcdecoder
static int oss_open(void)
{
   bool force_oss3 = false;
   ALLEGRO_CONFIG *config = al_get_system_config();
   if (config) {
      const char *force_oss3_cfg;
      force_oss3_cfg = al_get_config_value(config, "oss", "force_ver3");
      if (force_oss3_cfg && force_oss3_cfg[0] != '\0')
         force_oss3 = strcmp(force_oss3_cfg, "yes") ? false : true;
   }

   if (force_oss3) {
      ALLEGRO_WARN("Skipping OSS4 probe.\n");
   }

#ifdef OSS_VER_4
   bool inited = false;
   if (!force_oss3) {
      if (oss_open_ver4())
         ALLEGRO_WARN("OSS ver. 4 init failed, trying ver. 3...\n");
      else
         inited = true;
   }
   if (!inited && oss_open_ver3()) {
      ALLEGRO_ERROR("Failed to init OSS.\n");
      return 1;
   }
#else
   ALLEGRO_INFO("OSS4 support not compiled in. Skipping OSS4 probe.\n");
   if (oss_open_ver3()) {
      ALLEGRO_ERROR("Failed to init OSS.\n");
      return 1;
   }
#endif

   return 0;
}
예제 #12
0
/* Creates the default voice and mixer if they haven't been created yet. */
static bool create_default_mixer(void)
{
   int voice_frequency = 44100;
   int voice_depth = ALLEGRO_AUDIO_DEPTH_INT16;
   int mixer_frequency = 44100;
   int mixer_depth = ALLEGRO_AUDIO_DEPTH_FLOAT32;

   ALLEGRO_CONFIG *config = al_get_system_config();
   const char *p;
   p = al_get_config_value(config, "audio", "primary_voice_frequency");
   if (p && p[0] != '\0') {
      voice_frequency = atoi(p);
   }
   p = al_get_config_value(config, "audio", "primary_mixer_frequency");
   if (p && p[0] != '\0') {
      mixer_frequency = atoi(p);
   }
   p = al_get_config_value(config, "audio", "primary_voice_depth");
   if (p && p[0] != '\0') {
      voice_depth = string_to_depth(p);
   }
   p = al_get_config_value(config, "audio", "primary_mixer_depth");
   if (p && p[0] != '\0') {
      mixer_depth = string_to_depth(p);
   }

   if (!allegro_voice) {
      allegro_voice = al_create_voice(voice_frequency, voice_depth,
         ALLEGRO_CHANNEL_CONF_2);
      if (!allegro_voice) {
         ALLEGRO_ERROR("al_create_voice failed\n");
         goto Error;
      }
   }

   if (!allegro_mixer) {
      allegro_mixer = al_create_mixer(mixer_frequency, mixer_depth,
         ALLEGRO_CHANNEL_CONF_2);
      if (!allegro_mixer) {
         ALLEGRO_ERROR("al_create_voice failed\n");
         goto Error;
      }
   }

   /* In case this function is called multiple times. */
   al_detach_mixer(allegro_mixer);

   if (!al_attach_mixer_to_voice(allegro_mixer, allegro_voice)) {
      ALLEGRO_ERROR("al_attach_mixer_to_voice failed\n");
      goto Error;
   }

   return true;

Error:

   if (allegro_mixer) {
      al_destroy_mixer(allegro_mixer);
      allegro_mixer = NULL;
   }

   if (allegro_voice) {
      al_destroy_voice(allegro_voice);
      allegro_voice = NULL;
   }

   return false;
}
예제 #13
0
static ALLEGRO_DISPLAY_INTERFACE *win_get_display_driver(void)
{
    const int flags = al_get_new_display_flags();
    ALLEGRO_SYSTEM *sys = al_get_system_driver();
    ALLEGRO_CONFIG *sys_cfg = al_get_system_config();
    ALLEGRO_SYSTEM_WIN *syswin = (ALLEGRO_SYSTEM_WIN *)sys;
    const char *s;

    /* Look up the toggle_mouse_grab_key binding.  This isn't such a great place
     * to do it, but the config file is not available in win_initialize,
     * and this is neutral between the D3D and OpenGL display drivers.
     */
    if (!syswin->toggle_mouse_grab_keycode) {
        const char *binding = al_get_config_value(sys_cfg, "keyboard",
                              "toggle_mouse_grab_key");
        if (binding) {
            syswin->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
                                                &syswin->toggle_mouse_grab_modifiers);
            if (syswin->toggle_mouse_grab_keycode) {
                ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
            }
            else {
                ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
            }
        }
    }

    /* Programmatic selection. */
#ifdef ALLEGRO_CFG_D3D
    if (flags & ALLEGRO_DIRECT3D_INTERNAL) {
        ALLEGRO_DISPLAY_INTERFACE* iface = _al_display_d3d_driver();
        if (iface == NULL)
            ALLEGRO_WARN("Direct3D graphics driver not available.\n");
        return iface;
    }
#endif
#ifdef ALLEGRO_CFG_OPENGL
    if (flags & ALLEGRO_OPENGL) {
        return _al_display_wgl_driver();
    }
#endif

    /* Selection by configuration file.  The configuration value is non-binding.
     * The user may unknowingly set a value which was configured out at compile
     * time.  The value should have no effect instead of causing a failure.
     */
    s = al_get_config_value(sys_cfg, "graphics", "driver");
    if (s) {
        ALLEGRO_DEBUG("Configuration value graphics.driver = %s\n", s);
        if (0 == _al_stricmp(s, "DIRECT3D") || 0 == _al_stricmp(s, "D3D")) {
#ifdef ALLEGRO_CFG_D3D
            ALLEGRO_DISPLAY_INTERFACE* iface = _al_display_d3d_driver();
            if (iface != NULL) {
                al_set_new_display_flags(flags | ALLEGRO_DIRECT3D_INTERNAL);
                return iface;
            }
#endif
        }
        else if (0 == _al_stricmp(s, "OPENGL")) {
#ifdef ALLEGRO_CFG_OPENGL
            al_set_new_display_flags(flags | ALLEGRO_OPENGL);
            return _al_display_wgl_driver();
#endif
        }
        else if (0 != _al_stricmp(s, "DEFAULT")) {
            ALLEGRO_WARN("Graphics driver selection unrecognised: %s\n", s);
        }
    }

    /* Automatic graphics driver selection. */
    /* XXX is implicitly setting new_display_flags the desired behaviour? */
#ifdef ALLEGRO_CFG_D3D
    {
        ALLEGRO_DISPLAY_INTERFACE* iface = _al_display_d3d_driver();
        if (iface != NULL) {
            al_set_new_display_flags(flags | ALLEGRO_DIRECT3D_INTERNAL);
            return iface;
        }
    }
#endif
#ifdef ALLEGRO_CFG_OPENGL
    {
        al_set_new_display_flags(flags | ALLEGRO_OPENGL);
        return _al_display_wgl_driver();
    }
#endif
    ALLEGRO_WARN("No graphics driver available.\n");
    return NULL;
}
예제 #14
0
파일: menu.c 프로젝트: allefant/allegro5
/* Function: al_set_display_menu
 */
bool al_set_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu)
{
   DISPLAY_MENU *dm = NULL;
   size_t i;
   int menu_height = _al_get_menu_display_height();
   bool automatic_menu_display_resize = true;
   const char* automatic_menu_display_resize_value =
      al_get_config_value(al_get_system_config(), "compatibility", "automatic_menu_display_resize");
   if (automatic_menu_display_resize_value && strcmp(automatic_menu_display_resize_value, "false") == 0)
      automatic_menu_display_resize = false; 

   ASSERT(display);

   /* Check if this display has a menu associated with it */
   for (i = 0; i < _al_vector_size(&display_menus); ++i) {
      dm = (DISPLAY_MENU *) _al_vector_ref(&display_menus, i);
      if (dm->display == display)
         break;
   }

   /* If no display was found, reset dm to NULL */
   if (i == _al_vector_size(&display_menus))
      dm = NULL;

   if (!menu) {
      /* Removing the menu */

      if (!dm)
         return false;

      _al_hide_display_menu(display, dm->menu);
      _al_walk_over_menu(dm->menu, set_menu_display_r, NULL);
      _al_vector_delete_at(&display_menus, i);

      if (automatic_menu_display_resize && menu_height > 0) {
         display->extra_resize_height = 0;
         al_resize_display(display, al_get_display_width(display), al_get_display_height(display));
      }
   }
   else {
      /* Setting the menu. It must not currently be attached to any 
       * display, and it cannot have a parent menu. */
      if (menu->display || menu->parent)
         return false;

      if (dm) {
         /* hide the existing menu */
         _al_hide_display_menu(display, dm->menu);
         _al_walk_over_menu(dm->menu, set_menu_display_r, NULL);
      }

      if (!_al_show_display_menu(display, menu)) {
         /* Unable to set the new menu, but already have hidden the 
          * previous one, so delete the display_menus slot. */
         if (dm) 
            _al_vector_delete_at(&display_menus, i);
         return false;
      }

      /* Set the entire menu tree as owned by the display */
      _al_walk_over_menu(menu, set_menu_display_r, display);

      if (!dm)
         dm = _al_vector_alloc_back(&display_menus);

      if (automatic_menu_display_resize && menu_height > 0) {
         /* Temporarily disable the constraints so we don't send a RESIZE_EVENT. */
         bool old_constraints = display->use_constraints;
         display->use_constraints = false;
         display->extra_resize_height = menu_height;
         al_resize_display(display, al_get_display_width(display), al_get_display_height(display));
         display->use_constraints = old_constraints;
      }

      dm->display = display;
      dm->menu = menu;
   }

   return true;
}
예제 #15
0
static bool _al_xwin_get_keyboard_mapping(void)
{
    int i;
    int count;
    int missing = 0;

    ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();

    memset(used, 0, sizeof used);
    memset(keycode_to_scancode, 0, sizeof keycode_to_scancode);

    XDisplayKeycodes(system->x11display, &min_keycode, &max_keycode);
    count = 1 + max_keycode - min_keycode;

    if (keysyms) {
        XFree(keysyms);
    }
    keysyms = XGetKeyboardMapping(system->x11display, min_keycode,
                                  count, &sym_per_key);

    ALLEGRO_INFO("%i keys, %i symbols per key.\n", count, sym_per_key);

    if (sym_per_key <= 0) {
        return false;
    }

    missing = 0;

    for (i = min_keycode; i <= max_keycode; i++) {
        KeySym sym = keysyms[sym_per_key * (i - min_keycode)];
        KeySym sym2 =  keysyms[sym_per_key * (i - min_keycode) + 1];
        char *sym_str, *sym2_str;
        int allegro_key = 0;
        char str[1024];

        sym_str = XKeysymToString(sym);
        sym2_str = XKeysymToString(sym2);

        snprintf(str, sizeof str, "key [%i: %s %s]", i,
                 sym_str ? sym_str : "NULL", sym2_str ? sym2_str : "NULL");

        /* Hack for French keyboards, to correctly map ALLEGRO_KEY_0 to ALLEGRO_KEY_9. */
        if (sym2 >= XK_0 && sym2 <= XK_9) {
            allegro_key = find_allegro_key(sym2);
        }

        if (!allegro_key) {
            if (sym != NoSymbol) {
                allegro_key = find_allegro_key(sym);

                if (allegro_key == 0) {
                    missing++;
                    ALLEGRO_DEBUG("%s defering.\n", str);
                }
            }
            else {
                /* No KeySym for this key - ignore it. */
                keycode_to_scancode[i] = -1;
                ALLEGRO_DEBUG("%s not assigned.\n", str);
            }
        }

        if (allegro_key) {
            bool is_double = false;
            if (used[allegro_key]) {
                is_double = true;
            }
            keycode_to_scancode[i] = allegro_key;
            key_names[allegro_key] =
                XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
            used[allegro_key] = 1;
            ALLEGRO_DEBUG("%s%s assigned to %i.\n", str,
                          is_double ? " *double*" : "", allegro_key);
        }
    }

    if (missing) {
        /* The keys still not assigned are just assigned arbitrarily now. */
        for (i = min_keycode; i <= max_keycode; i++) {
            if (keycode_to_scancode[i] == 0) {
                find_unknown_key_assignment(i);
            }
        }
    }

    if (xmodmap)
        XFreeModifiermap(xmodmap);
    xmodmap = XGetModifierMapping(system->x11display);
    for (i = 0; i < 8; i++) {
        int j;
        char str[1024];
        sprintf(str, "Modifier %d:", i + 1);
        for (j = 0; j < xmodmap->max_keypermod; j++) {
            KeyCode keycode = xmodmap->modifiermap[i * xmodmap->max_keypermod + j];
            // XKeycodeToKeysym is deprecated
            //KeySym sym = XKeycodeToKeysym(system->x11display, keycode, 0);
            KeySym sym = XkbKeycodeToKeysym(system->x11display, keycode, 0, 0);

            char *sym_str = XKeysymToString(sym);
            sprintf(str + strlen(str), " %s", sym_str ? sym_str : "NULL");
        }
        ALLEGRO_DEBUG("%s\n", str);
    }

    /* The [xkeymap] section can be useful, e.g. if trying to play a
     * game which has X and Y hardcoded as ALLEGRO_KEY_X and ALLEGRO_KEY_Y to mean
     * left/right movement, but on the X11 keyboard X and Y are far apart.
     * For normal use, a user never should have to touch [xkeymap] anymore
     * though, and proper written programs will not hardcode such mappings.
     */
    ALLEGRO_CONFIG *c = al_get_system_config();

    char const *key;
    ALLEGRO_CONFIG_ENTRY *it;
    key = al_get_first_config_entry(c, "xkeymap", &it);
    while (key) {
        char const *val;
        val = al_get_config_value(c, "xkeymap", key);
        int keycode = strtol(key, NULL, 10);
        int scancode = strtol(val, NULL, 10);
        if (keycode > 0 && scancode > 0) {
            keycode_to_scancode[keycode] = scancode;
            ALLEGRO_WARN("User override: KeySym %i assigned to %i.\n",
                         keycode, scancode);
        }
        key = al_get_next_config_entry(&it);
    }

    return true;
}
예제 #16
0
static int pulseaudio_allocate_voice(ALLEGRO_VOICE *voice)
{
   PULSEAUDIO_VOICE *pv = al_malloc(sizeof(PULSEAUDIO_VOICE));
   pa_sample_spec ss;
   pa_buffer_attr ba;

   ss.channels = al_get_channel_count(voice->chan_conf);
   ss.rate = voice->frequency;

   if (voice->depth == ALLEGRO_AUDIO_DEPTH_UINT8)
      ss.format = PA_SAMPLE_U8;
   else if (voice->depth == ALLEGRO_AUDIO_DEPTH_INT16)
      ss.format = PA_SAMPLE_S16NE;
#if PA_API_VERSION > 11
   else if (voice->depth == ALLEGRO_AUDIO_DEPTH_INT24)
      ss.format = PA_SAMPLE_S24NE;
#endif
   else if (voice->depth == ALLEGRO_AUDIO_DEPTH_FLOAT32)
      ss.format = PA_SAMPLE_FLOAT32NE;
   else {
      ALLEGRO_ERROR("Unsupported PulseAudio sound format.\n");
      al_free(pv);
      return 1;
   }

   ba.maxlength = 0x10000; // maximum length of buffer
   ba.tlength   = 0x2000;  // target length of buffer
   ba.prebuf    = -1;      // minimum data size required before playback starts
                           // set to -1 to work with the simple API.
   ba.minreq    = 0;       // minimum size of request 
   ba.fragsize  = -1;      // fragment size (recording)

   pv->s = pa_simple_new(
      NULL,                // Use the default server.
      al_get_app_name(),     
      PA_STREAM_PLAYBACK,
      NULL,                // Use the default device.
      "Allegro Voice",    
      &ss,                
      NULL,                // Use default channel map
      &ba,                
      NULL                 // Ignore error code.
   );

   if (!pv->s) {
      al_free(pv);
      return 1;
   }

   voice->extra = pv;

   pv->buffer_size_in_frames = get_buffer_size(al_get_system_config());
   pv->frame_size_in_bytes = ss.channels * al_get_audio_depth_size(voice->depth);

   pv->status = PV_IDLE;
   //pv->status_mutex = al_create_mutex();
   pv->status_cond = al_create_cond();
   pv->buffer_mutex = al_create_mutex();

   pv->poll_thread = al_create_thread(pulseaudio_update, (void*)voice);
   al_start_thread(pv->poll_thread);

   return 0;
}
예제 #17
0
파일: lkeybdnu.c 프로젝트: allefant/allegro
/* lkeybd_init_keyboard: [primary thread]
 *  Initialise the keyboard driver.
 */
static bool lkeybd_init_keyboard(void)
{
   bool can_restore_termio_and_kbmode = false;

   memset(&the_keyboard, 0, sizeof the_keyboard);

/*
   if (__al_linux_use_console())
      return false;
*/
   the_keyboard.fd = open("/dev/tty", O_RDWR);

   /* Save the current terminal attributes, which we will restore when
    * we close up shop.
    */
   if (tcgetattr(the_keyboard.fd, &the_keyboard.startup_termio) != 0) {
      goto Error;
   }

   /* Save previous keyboard mode (probably XLATE). */
   if (ioctl(the_keyboard.fd, KDGKBMODE, &the_keyboard.startup_kbmode) != 0) {
      //goto Error;
   }

   can_restore_termio_and_kbmode = false;

   /* Set terminal attributes we need.
    *
    * Input modes (c_iflag): We want to disable:
    *  - stripping bytes to 7 bits
    *  - ignoring of carriage returns
    *  - translating of carriage returns to newlines, and vice versa
    *  - start/stop control on input and output
    *
    * Control modes (c_cflag): We want 8 bits per byte.
    *
    * Local modes (c_lflag: We want to disable:
    *  - canonical (line by line) input
    *  - echoing input back to the display
    *  - interpretation of signal characters
    *
    * The c_iflag, c_lflag settings come from svgalib. Allegro 4
    * simply set them to 0, which is a bit crude.
    */
   the_keyboard.work_termio = the_keyboard.startup_termio;
   the_keyboard.work_termio.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
   the_keyboard.work_termio.c_cflag &= ~CSIZE;
   the_keyboard.work_termio.c_cflag |= CS8;
   the_keyboard.work_termio.c_lflag &= ~(ICANON | ECHO | ISIG);

   if (tcsetattr(the_keyboard.fd, TCSANOW, &the_keyboard.work_termio) != 0) {
      goto Error;
   }

   /* Set the keyboard mode to mediumraw. */
   if (ioctl(the_keyboard.fd, KDSKBMODE, K_MEDIUMRAW) != 0) {
      //goto Error;
   }

   the_keyboard.three_finger_flag = true;
   the_keyboard.key_led_flag = true;

   const char *value = al_get_config_value(al_get_system_config(),
         "keyboard", "enable_three_finger_exit");
   if (value) {
      the_keyboard.three_finger_flag = !strncmp(value, "true", 4);
   }
   value = al_get_config_value(al_get_system_config(),
         "keyboard", "enable_key_led_toggle");
   if (value) {
      the_keyboard.key_led_flag = !strncmp(value, "true", 4);
   }

   ALLEGRO_DEBUG("Three finger flag enabled: %s\n",
      the_keyboard.three_finger_flag ? "true" : "false");
   ALLEGRO_DEBUG("Key LED toggle enabled: %s\n",
      the_keyboard.key_led_flag ? "true" : "false");

   /* Initialise the keyboard object for use as an event source. */
   _al_event_source_init(&the_keyboard.parent.es);

   /* Start watching for data on the fd. */
   _al_unix_start_watching_fd(the_keyboard.fd, process_new_data, NULL);

   /* Get the pid, which we use for the three finger salute */
   main_pid = getpid();

   return true;

  Error:

   if (can_restore_termio_and_kbmode) {
      tcsetattr(the_keyboard.fd, TCSANOW, &the_keyboard.startup_termio);
      ioctl(the_keyboard.fd, KDSKBMODE, the_keyboard.startup_kbmode);
   }

   close(the_keyboard.fd);

/*
   __al_linux_leave_console();
*/

   return false;
}
예제 #18
0
파일: xsystem.c 프로젝트: allefant/allegro
static ALLEGRO_SYSTEM *xglx_initialize(int flags)
{
   Display *x11display;
   Display *gfxdisplay;
   ALLEGRO_SYSTEM_XGLX *s;

   (void)flags;

#ifdef DEBUG_X11
   _Xdebug = 1;
#endif

   XInitThreads();

   /* Get an X11 display handle. */
   x11display = XOpenDisplay(0);
   if (x11display) {
      /* Never ask. */
      gfxdisplay = XOpenDisplay(0);
      if (!gfxdisplay) {
         ALLEGRO_ERROR("XOpenDisplay failed second time.\n");
         XCloseDisplay(x11display);
         return NULL;
      }
   }
   else {
      ALLEGRO_INFO("XOpenDisplay failed; assuming headless mode.\n");
      gfxdisplay = NULL;
   }
   
   _al_unix_init_time();

   s = al_calloc(1, sizeof *s);

   _al_mutex_init_recursive(&s->lock);
   _al_cond_init(&s->resized);
   s->inhibit_screensaver = false;

   _al_vector_init(&s->system.displays, sizeof (ALLEGRO_DISPLAY_XGLX *));

   s->system.vt = xglx_vt;

   s->gfxdisplay = gfxdisplay;
   s->x11display = x11display;

   if (s->x11display) {
      ALLEGRO_INFO("XGLX driver connected to X11 (%s %d).\n",
         ServerVendor(s->x11display), VendorRelease(s->x11display));
      ALLEGRO_INFO("X11 protocol version %d.%d.\n",
         ProtocolVersion(s->x11display), ProtocolRevision(s->x11display));

      /* We need to put *some* atom into the ClientMessage we send for
       * faking mouse movements with al_set_mouse_xy - so let's ask X11
       * for one here.
       */
      s->AllegroAtom = XInternAtom(x11display, "AllegroAtom", False);

      /* Message type for XEmbed protocol. */
      s->XEmbedAtom = XInternAtom(x11display, "_XEMBED", False);

      _al_thread_create(&s->xevents_thread, _al_xwin_background_thread, s);
      s->have_xevents_thread = true;
      ALLEGRO_INFO("events thread spawned.\n");
   }

   const char *binding = al_get_config_value(al_get_system_config(),
         "keyboard", "toggle_mouse_grab_key");
   if (binding) {
      s->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
         &s->toggle_mouse_grab_modifiers);
      if (s->toggle_mouse_grab_keycode) {
         ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
      }
      else {
         ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
      }
   }

#ifdef ALLEGRO_XWINDOWS_WITH_XPM
   x11_xpm = icon_xpm;
#endif

   return &s->system;
}