static void
bind_keys_qwertz(PianoKeyboard *pk)
{
	bind_keys_qwerty(pk);

	/* The only difference between QWERTY and QWERTZ is that the "y" and "z" are swapped together. */
	bind_key(pk, "y", 12);
	bind_key(pk, "z", 33);
}
Exemple #2
0
 void key_listener::bind_key(int logical_key, const SDLKey& k, 
                             const SDLMod& m, bool collapse_doubles) {
     SDL_keysym sym;
     sym.sym = k;
     sym.mod = m;
     bind_key(logical_key, sym, collapse_doubles);
 }
sqlite3_stmt *YesqlClient::construct_sql_scan(const TableId& table, const Key& start_key, int count,
				const FieldList& fields){
  sqlite3_stmt* ret = nullptr;
  std::string sql;
  bool prepared = false;
  sql.append("SELECT ");
  for (auto& it : fields){
    sql.append(it);
    sql.append(",");
  }
  sql.back() = ' ';
  sql.append(" FROM ");
  sql.append(table);
  sql.append(" WHERE ");
  sql.append(KEYNAME);
  sql.append(">=?");
  sql.append(" LIMIT ");
  char num_buf[10];
  snprintf(num_buf, 10, "%d", count);
  sql.append(num_buf);

  int rc = stmt_cache(STMT_INDEX_SCAN, sql.c_str(), &ret);
  if (rc == SQLITE_OK){
    prepared = true;
    rc = bind_key(ret, start_key);
  }
  if (rc != SQLITE_OK){
    LOG("Error %s scan: %s\n\tSQL was: %s\n", (prepared) ? "binding" : "preparing",
	            sqlite3_errmsg(_dbhandle), sql.c_str());
    //sqlite3_finalize(ret);
    ret = nullptr;
  }
  return ret;
}
sqlite3_stmt *YesqlClient::construct_sql_read(const TableId& table, const Key& key, const FieldList& fields){
  sqlite3_stmt* ret = nullptr;
  bool prepared = false;
  int rc=0;
  std::string sql;

  sql.append("SELECT ");
  for (auto& it : fields){
    sql.append(it);
    sql.append(",");
  }
  sql.back() = ' ';
  sql.append(" FROM ");
  sql.append(table);
  sql.append(" WHERE ");
  sql.append(KEYNAME);
  sql.append("=?");

  rc = stmt_cache(STMT_INDEX_READ, sql.c_str(), &ret);
  
  if (rc == SQLITE_OK){
    prepared = true;
    rc = bind_key(ret, key);
  }
  if (rc != SQLITE_OK){
    if (sql == "") sql.append("(previously-prepared-query)");
    LOG("Error %s read: %s\n\tSQL was: %s\n", (prepared) ? "binding" : "preparing",
	            sqlite3_errmsg(_dbhandle), sql.c_str());
    //sqlite3_finalize(ret);
    ret = nullptr;
  }
  return ret;
}
void
JoystickKeyboardController::process_menu_key_event(const SDL_KeyboardEvent& event)
{
  // wait for key mode?
  if(wait_for_key >= 0) {
    if(event.type == SDL_KEYUP)
      return;

    if(event.keysym.sym != SDLK_ESCAPE
       && event.keysym.sym != SDLK_PAUSE) {
      bind_key(event.keysym.sym, Control(wait_for_key));
    }
    reset();
    MenuStorage::get_key_options_menu()->update();
    wait_for_key = -1;
    return;
  }
  if(wait_for_joystick >= 0) {
    if(event.keysym.sym == SDLK_ESCAPE) {
      reset();
      MenuStorage::get_joystick_options_menu()->update();
      wait_for_joystick = -1;
    }
    return;
  }

  Control control;
  /* we use default keys when the menu is open (to avoid problems when
   * redefining keys to invalid settings
   */
  switch(event.keysym.sym) {
    case SDLK_UP:
      control = Controller::UP;
      break;
    case SDLK_DOWN:
      control = Controller::DOWN;
      break;
    case SDLK_LEFT:
      control = Controller::LEFT;
      break;
    case SDLK_RIGHT:
      control = Controller::RIGHT;
      break;
    case SDLK_SPACE:
    case SDLK_RETURN:
    case SDLK_KP_ENTER:
      control = Controller::MENU_SELECT;
      break;
    case SDLK_ESCAPE:
    case SDLK_PAUSE:
      control = Controller::PAUSE_MENU;
      break;
    default:
      return;
      break;
  }

  controller->set_control(control, (event.type == SDL_KEYDOWN));
}
Exemple #6
0
/*
 * Try to get a handle to a readline function from a variety of different
 * libraries.  If nothing is present on the system, then fall back to an
 * internal one.
 *
 * Logic originally based off of code in the e2fsutils package in the
 * lib/ss/get_readline.c file, which is licensed under the MIT license.
 *
 * This keeps us from having to relicense the bti codebase if readline
 * ever changes its license, as there is no link-time dependency.
 * It is a run-time thing only, and we handle any readline-like library
 * in the same manner, making bti not be a derivative work of any
 * other program.
 */
static void session_readline_init(struct session *session)
{
	/* Libraries we will try to use for readline/editline functionality */
	const char *libpath = "libreadline.so.6:libreadline.so.5:"
	    "libreadline.so.4:libreadline.so:libedit.so.2:"
	    "libedit.so:libeditline.so.0:libeditline.so";
	void *handle = NULL;
	char *tmp, *cp, *next;
	int (*bind_key) (int, void *);
	void (*insert) (void);

	/* default to internal function if we can't or won't find anything */
	session->readline = get_string;
	if (!isatty(0))
		return;
	session->interactive = 1;

	tmp = malloc(strlen(libpath) + 1);
	if (!tmp)
		return;
	strcpy(tmp, libpath);
	for (cp = tmp; cp; cp = next) {
		next = strchr(cp, ':');
		if (next)
			*next++ = 0;
		if (*cp == 0)
			continue;
		handle = dlopen(cp, RTLD_NOW);
		if (handle) {
			dbg("Using %s for readline library\n", cp);
			break;
		}
	}
	free(tmp);
	if (!handle) {
		dbg("No readline library found.\n");
		return;
	}

	session->readline_handle = handle;
	session->readline = (char *(*)(const char *))dlsym(handle, "readline");
	if (session->readline == NULL) {
		/* something odd happened, default back to internal stuff */
		session->readline_handle = NULL;
		session->readline = get_string;
		return;
	}

	/*
	 * If we found a library, turn off filename expansion
	 * as that makes no sense from within bti.
	 */
	bind_key = (int (*)(int, void *))dlsym(handle, "rl_bind_key");
	insert = (void (*)(void))dlsym(handle, "rl_insert");
	if (bind_key && insert)
		bind_key('\t', insert);
}
Exemple #7
0
    void key_listener::expand_keys(int logical_key, const SDL_keysym& sym,
                                   const SDLMod& processed_mask, int depth) {
        SDL_keysym tmp;
        tmp = sym;

        static const int NUM_CHUNKS = 4;
        static const SDLMod chunks[NUM_CHUNKS] = { 
            (SDLMod)KMOD_SHIFT, (SDLMod)KMOD_ALT, 
            (SDLMod)KMOD_CTRL,  (SDLMod)KMOD_META 
        };
        static const SDLMod ALL_CHUNKS = (SDLMod)(KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_META);

        static const int NUM_BITS = sizeof(SDLMod)*8;
        int bit_idx[NUM_BITS];

        int remaining = ALL_CHUNKS & sym.mod & ~processed_mask;
        if(remaining == 0) {
            bind_key(logical_key, sym, false);
            return;
        } 

        for(int i =0;i<NUM_CHUNKS;++i) {
            if(sym.mod & chunks[i] && !(processed_mask & chunks[i])) {
                SDLMod newmask = (SDLMod)(processed_mask | chunks[i]);
                SDLMod newmod = (SDLMod)(sym.mod & ~chunks[i]);

                int bit_count = 0;
                for(int j=0;j<NUM_BITS;++j) {
                    if(chunks[i] & (1 << j)) {
                        bit_idx[bit_count++] = j;
                    }
                }
                int k_max = 1 << bit_count;
                for(int k=1;k < k_max;++k) {
                    tmp.mod = newmod;
                    for(int j=0;j<bit_count;++j) {
                        int bit = 1 << j;
                        if(k & bit) {
                            tmp.mod = (SDLMod)(tmp.mod | (1 << bit_idx[j]));
                        }
                    }
                    expand_keys(logical_key, tmp, newmask, depth+1);
                }
                return;
            }
        }
    }        
Exemple #8
0
static SCM scm_bind_key(SCM mod_mask, SCM key, SCM proc)
{
    xcb_keysym_t keysym;
    if (scm_is_true(scm_number_p(key)))
        keysym = scm_to_uint32(key);
    else if (scm_is_true(scm_string_p(key))) {
        scm_dynwind_begin(0);
        char *c_key = scm_to_locale_string(key);
        scm_dynwind_free(c_key);
        keysym = get_keysym(c_key);
        scm_dynwind_end();
    }
    else
        return SCM_UNSPECIFIED;
    bind_key(scm_to_uint16(mod_mask), keysym, proc);
    return SCM_UNSPECIFIED;
}
sqlite3_stmt *YesqlClient::construct_sql_remove(const TableId& table, const Key& key){
  sqlite3_stmt* ret;
  bool prepared = false;
  std::string sql;
  sql.append("DELETE FROM ");
  sql.append(table);
  sql.append(" WHERE ");
  sql.append(KEYNAME);
  sql.append("=?");
  
  int rc = stmt_cache(STMT_INDEX_REMOVE, sql.c_str(), &ret);
  
  if (rc == SQLITE_OK){
    rc = bind_key(ret, key);
  }
  if (rc != SQLITE_OK){
    LOG("Error %s delete: %s\n\tSQL was: %s\n", (prepared) ? "binding" : "preparing",
	            sqlite3_errmsg(_dbhandle), sql.c_str());
    //sqlite3_finalize(ret);
    ret = nullptr;
  }
  return ret;
}
static void
bind_keys_azerty(PianoKeyboard *pk)
{
	clear_notes(pk);

	bind_key(pk, "space", 128);

	/* Lower keyboard row - "wxcvbn,". */
	bind_key(pk, "w", 12);	/* C0 */
	bind_key(pk, "s", 13);
	bind_key(pk, "x", 14);
	bind_key(pk, "d", 15);
	bind_key(pk, "c", 16);
	bind_key(pk, "v", 17);
	bind_key(pk, "g", 18);
	bind_key(pk, "b", 19);
	bind_key(pk, "h", 20);
	bind_key(pk, "n", 21);
	bind_key(pk, "j", 22);
	bind_key(pk, "comma", 23);

	/* Upper keyboard row, first octave - "azertyu". */
	bind_key(pk, "a", 24);
	bind_key(pk, "eacute", 25);
	bind_key(pk, "z", 26);
	bind_key(pk, "quotedbl", 27);
	bind_key(pk, "e", 28);
	bind_key(pk, "r", 29);
	bind_key(pk, "parenleft", 30);
	bind_key(pk, "t", 31);
	bind_key(pk, "minus", 32);
	bind_key(pk, "y", 33);
	bind_key(pk, "egrave", 34);
	bind_key(pk, "u", 35);

	/* Upper keyboard row, the rest - "iop". */
	bind_key(pk, "i", 36);
	bind_key(pk, "ccedilla", 37);
	bind_key(pk, "o", 38);
	bind_key(pk, "agrave", 39);
	bind_key(pk, "p", 40);
}
static void
bind_keys_qwerty(PianoKeyboard *pk)
{
	clear_notes(pk);

	bind_key(pk, "space", 128);

	/* Lower keyboard row - "zxcvbnm". */
	bind_key(pk, "z", 12);	/* C0 */
	bind_key(pk, "s", 13);
	bind_key(pk, "x", 14);
	bind_key(pk, "d", 15);
	bind_key(pk, "c", 16);
	bind_key(pk, "v", 17);
	bind_key(pk, "g", 18);
	bind_key(pk, "b", 19);
	bind_key(pk, "h", 20);
	bind_key(pk, "n", 21);
	bind_key(pk, "j", 22);
	bind_key(pk, "m", 23);

	/* Upper keyboard row, first octave - "qwertyu". */
	bind_key(pk, "q", 24);
	bind_key(pk, "2", 25);
	bind_key(pk, "w", 26);
	bind_key(pk, "3", 27);
	bind_key(pk, "e", 28);
	bind_key(pk, "r", 29);
	bind_key(pk, "5", 30);
	bind_key(pk, "t", 31);
	bind_key(pk, "6", 32);
	bind_key(pk, "y", 33);
	bind_key(pk, "7", 34);
	bind_key(pk, "u", 35);

	/* Upper keyboard row, the rest - "iop". */
	bind_key(pk, "i", 36);
	bind_key(pk, "9", 37);
	bind_key(pk, "o", 38);
	bind_key(pk, "0", 39);
	bind_key(pk, "p", 40);
}
Exemple #12
0
bool Keybinding_pool::load_from(std::string filename)
{
  std::ifstream fin;
  fin.open(filename.c_str());
  if (!fin.is_open()) {
    debugmsg("Failed to open '%s'", filename.c_str());
    return false;
  }
  std::string keystr;
  std::vector<long> keys;
  while (!fin.eof() && fin >> keystr) {
    if (lookup_key(keystr) != 0) {
      keys.push_back( lookup_key(keystr) );
    } else if (keystr == "=") {
      std::string action_name;
      std::getline(fin, action_name);
      action_name = trim(action_name);
      Interface_action act = lookup_interface_action(action_name);
      if (act == IACTION_NULL) {

        Debug_action debug_act = lookup_debug_action(action_name);

        if (debug_act == DEBUG_ACTION_NULL) {
          debugmsg("Unknown action in '%s': '%s'", filename.c_str(),
                   action_name.c_str());

        } else {
          for (int i = 0; i < keys.size(); i++) {
            Debug_action already_bound = bound_to_debug_key( keys[i] );
            if (already_bound != DEBUG_ACTION_NULL) {
              debugmsg("Key %c bound to %s; reassigned to %s. (%s)", keys[i],
                       debug_action_name(already_bound).c_str(),
                       debug_action_name(debug_act).c_str(),
                       filename.c_str());
            }
            bind_debug_key( keys[i], debug_act );
          }
        }

      } else {  // if (act == IACTION_NULL)
        for (int i = 0; i < keys.size(); i++) {
          Interface_action already_bound = bound_to_key( keys[i] );
          if (already_bound != IACTION_NULL) {
            debugmsg("Key %c bound to %s; reassigned to %s. (%s)", keys[i],
                     interface_action_name(already_bound).c_str(),
                     interface_action_name(act).c_str(),
                     filename.c_str());
          }
          bind_key( keys[i], act );
        }
      }

      keys.clear();

    } else {
      for (int i = 0; i < keystr.size(); i++) {
        keys.push_back( keystr[i] );
      }
    }
  }
  return true;
}