Beispiel #1
0
/**
Look ahead function to test whether a dictionary matches a condition
*/
t_bool _dict_recurse_match_dict(t_dict_recurse *x, t_dictionary *dict, t_symbol **key_match, t_symbol **value_match)
{
  TRACE("_dict_recurse_match_dict");

  // Get the dictionary keys
  long  key_cnt = 0;
  t_symbol **key_arr = NULL;
  t_symbol *key = gensym("");
  t_atom value[1];

  *key_match = gensym("");
  *value_match = gensym("");

  dictionary_getkeys(dict, &key_cnt, &key_arr);

  t_bool test = false;
  for (t_int32 ind = 0; ind < key_cnt; ind++) {

    key = key_arr[ind];

    if (!regexpr_match(x->search_key_expr, key)) { continue; }

    dictionary_getatom(dict, key, value);
    if (regexpr_match(x->search_val_expr, atom_getsym(value))) {
      test = true;
      *key_match = key;
      *value_match = atom_getsym(value);
      break; } }

  if (key_arr) { dictionary_freekeys(dict, key_cnt, key_arr); }
  
  return test;
}
Beispiel #2
0
void tralala_mouseReleaseLasso(t_tll *x)
{
    long i, n = 0;
    t_symbol **keys = NULL;
    
    TLL_DATA_LOCK
    
    if (!(dictionary_getkeys(x->current, &n, &keys))) {
    //
    long argc;
    t_atom *argv = NULL;
    
    for (i = 0; i < n; i++) {
    //
    long status = 0;
    t_symbol *key = (*(keys + i));
    
    if (!(dictionary_getatoms(x->current, key, &argc, &argv))) { 
        if ((atom_getsym(argv) == TLL_SYM_NOTE) && (!dictionary_getlong(x->status, key, &status))) {
            if (status == TLL_LASSO_UNSELECTED) {
                dictionary_deleteentry(x->status, key);
            } else {
                dictionary_appendlong(x->status, key, TLL_SELECTED);
            }
        }
    }
    //
    }
    
    dictionary_freekeys(x->current, n, keys);
    //
    }
    
    TLL_DATA_UNLOCK
    
    TLL_FLAG_UNSET(TLL_FLAG_LASSO);
}
Beispiel #3
0
ulong tralala_mouseSelectLasso(t_tll *x)
{
    long i, n = 0;
    t_symbol **keys = NULL;
    ulong dirty = TLL_FLAG_NONE;
    
    TLL_DATA_LOCK
    
    if (!(dictionary_getkeys(x->current, &n, &keys))) {
    //
    long argc;
    t_atom *argv = NULL;
    
    double c[ ] = { TLL_X_OFFSET(MIN(x->origin.x, x->cursor.x)), TLL_Y_OFFSET(MIN(x->origin.y, x->cursor.y)),
                    TLL_X_OFFSET(MAX(x->origin.x, x->cursor.x)), TLL_Y_OFFSET(MAX(x->origin.y, x->cursor.y)) };
    
    for (i = 0; i < n; i++) {
    //
    t_symbol *key = (*(keys + i));
    
    if (!(dictionary_getatoms(x->current, key, &argc, &argv)) && ((atom_getsym(argv) == TLL_SYM_NOTE))) { 
    //
    long status = 0;
    double a = TLL_POSITION_TO_X(atom_getlong(argv + 1));
    double b = TLL_PITCH_TO_Y_UP(atom_getlong(argv + 2));
    double u = TLL_POSITION_TO_X(atom_getlong(argv + 1) + atom_getlong(argv + 4));
    double v = TLL_PITCH_TO_Y_DOWN(atom_getlong(argv + 2));
    bool k = false;
        
    k =  ((a > c[0]) && (a < c[2])) || ((u > c[0]) && (u < c[2]));
    k &= ((b > c[1]) && (b < c[3])) || ((v > c[1]) && (v < c[3]));
    
    if (k) {

        if (!(dictionary_hasentry(x->status, key))) {
            dictionary_appendlong(x->status, key, TLL_LASSO_SELECTED);
            dirty |= TLL_DIRTY_NOTE;
            
        } else if (TLL_FLAG_TRUE(TLL_FLAG_SHIFT)) {
            if (!(dictionary_getlong(x->status, key, &status)) && (status == TLL_SELECTED)) {
                dictionary_appendlong(x->status, key, TLL_LASSO_UNSELECTED);
                dirty |= TLL_DIRTY_NOTE;
            }
        }
        
    } else if (!(dictionary_getlong(x->status, key, &status))) {
    
        if (status == TLL_LASSO_SELECTED) {
            dictionary_deleteentry(x->status, key);
            dirty |= TLL_DIRTY_NOTE;
            
        } else if ((TLL_FLAG_TRUE(TLL_FLAG_SHIFT)) && (status == TLL_LASSO_UNSELECTED)) {
            dictionary_appendlong(x->status, key, TLL_SELECTED);
            dirty |= TLL_DIRTY_NOTE;
        }
    }
    //
    }
    //
    }
    
    dictionary_freekeys(x->current, n, keys);
    //
    }
    
    TLL_DATA_UNLOCK
        
    return dirty;
}
Beispiel #4
0
long tralala_mouseHitNote(t_tll *x, long m)
{
    long i, n = 0;
    t_symbol *s = NULL;
    t_symbol *mark = NULL;
    t_symbol **keys = NULL;
    long position = TLL_X_TO_POSITION(x->cursor.x - 1.);
    long pitch = TLL_Y_TO_PITCH(x->cursor.y - 1.);
    long k = TLL_HIT_NONE;
        
    TLL_DATA_LOCK
    
    dictionary_deleteentry(x->status, TLL_SYM_ZONE);
    
    if (!(dictionary_getkeys(x->current, &n, &keys))) {
    //
    long argc;
    t_atom *argv = NULL;
    
    for (i = 0; i < n; i++) {
        t_symbol *key = (*(keys + i));
        if (!(dictionary_getatoms(x->current, key, &argc, &argv))) { 
            if ((atom_getsym(argv) == TLL_SYM_NOTE)) {
                long p = atom_getlong(argv + 2);
                long a = atom_getlong(argv + 1);
                long b = a + atom_getlong(argv + 4);
                if ((pitch == p) && (position >= a) && (position <= b)) {
                    s = key;
                    break;
                }
            }
        }
    }
    
    dictionary_freekeys(x->current, n, keys);
    //
    }
    
    if (s) {
        if (dictionary_hasentry(x->status, s)) {
            if (m & eShiftKey) {
                k = TLL_HIT_SWAP;
            } else {
                k = TLL_HIT_GRAB;
            }
        } else {
            k = TLL_HIT_PULL;
        }
    } 
    
    if (!(m & eShiftKey) && ((k == TLL_HIT_NONE) || (k == TLL_HIT_PULL))) {
        dictionary_clear(x->status);
    }
    
    if (k == TLL_HIT_SWAP) {
        if(!(dictionary_getsym(x->status, TLL_SYM_MARK, &mark)) && (s == mark)) {
            dictionary_deleteentry(x->status, TLL_SYM_MARK); 
        }
        dictionary_deleteentry(x->status, s);
        
    } else if (k == TLL_HIT_GRAB) {
        dictionary_appendsym(x->status, TLL_SYM_MARK, s);
        
    } else if (k == TLL_HIT_PULL) {
        dictionary_appendsym(x->status, TLL_SYM_MARK, s);
        dictionary_appendlong(x->status, s, TLL_SELECTED);
    }
    
    TLL_DATA_UNLOCK
    
    return k;
}
Beispiel #5
0
void tralala_paintCurrent(t_tll *x, t_object *pv)
{
    long zoneStatus = 0;
    long i, argc, n = 0;
    t_atom *argv = NULL;
    t_symbol *mark = NULL;
    t_symbol **keys = NULL;
    PIZError err = PIZ_GOOD;
    
    char string[TLL_STRING_SIZE] = "";
    
    t_symbol *s[ ] = { 
        TLL_SYM_BPM, 
        TLL_SYM_CHANCE, 
        TLL_SYM_VELOCITY, 
        TLL_SYM_CHANNEL, 
        TLL_SYM_CHORD,
        TLL_SYM_CELL, 
        TLL_SYM_VALUE, 
        TLL_SYM_SCALE
        };
    
    pizArrayClear(x->temp[0]);
    pizArrayClear(x->temp[1]);
    pizArrayClear(x->temp[2]);
    
    TLL_DATA_LOCK
    
    dictionary_getlong(x->status, TLL_SYM_ZONE, &zoneStatus);
    
    for (i = 0; i < 9; i++) {
        if (!(dictionary_getatoms(x->current, s[i], &argc, &argv)) && (argc > 1)) {
            tralala_paintStrncatPanel(string, argc, argv);
        }
    }
    
    if (!(dictionary_getatoms(x->current, TLL_SYM_MUTE, &argc, &argv)) 
        && (argc > 1)
        && (atom_gettype(argv + 1) == A_LONG)
        && (atom_getlong(argv + 1) == 1)) {
        strncat_zero(string, "•\n", TLL_STRING_SIZE);
    } else {
        strncat_zero(string, "\n", TLL_STRING_SIZE);
    }
    
    if (dictionary_hasentry(x->status, TLL_SYM_ZONE)) {
        if (!(dictionary_getatoms(x->current, TLL_SYM_ZONE, &argc, &argv))) {
            tralala_paintStrncatZone(string, argc, argv, zoneStatus);
        } 
    } else if (!(dictionary_getsym(x->status, TLL_SYM_MARK, &mark)) 
        && (!(dictionary_getatoms(x->current, mark, &argc, &argv)))) {
        tralala_paintStrncatNote(string, argc, argv);
    }
    
    if (!(dictionary_getkeys(x->current, &n, &keys))) {
    //
    for (i = 0; i < n; i++) {
    //
    long k, j, p, status = 0; 
    t_symbol *key = (*(keys + i));
    
    if (!(dictionary_getatoms(x->current, key, &argc, &argv)) 
        && (atom_getsym(argv) == TLL_SYM_NOTE)
        && (argc == 6)) { 
        if (k = dictionary_hasentry(x->status, key)) {
           dictionary_getlong(x->status, key, &status);
        }
        if (!k || (status == TLL_LASSO_UNSELECTED)) {
            p = 0;
        } else if (key != mark) {
            p = 1;
        } else {
            p = 2;
        }
        for (j = 1; j < 5; j++) {
            pizArrayAppend(x->temp[p], atom_getlong(argv + j));
        }
    }
    //
    }

    dictionary_freekeys(x->current, n, keys);
    //
    }
    
    err |= (dictionary_getatoms(x->current, TLL_SYM_ZONE, &argc, &argv)) != MAX_ERR_NONE;
    
    TLL_DATA_UNLOCK 
    
    if (!err) {
        if (!zoneStatus) {
            tralala_paintCurrentZone(x, pv, argc, argv, zoneStatus);
            tralala_paintCurrentNote(x, pv);
        } else {
            tralala_paintCurrentNote(x, pv);
            tralala_paintCurrentZone(x, pv, argc, argv, zoneStatus);
        }
        
        if (x->viewText) {
            tralala_paintCurrentText(x, pv, string);
        }
    }
}
Beispiel #6
0
void _dict_recurse_dict(t_dict_recurse *x, t_dictionary *dict, t_int32 depth)
{
  TRACE("_dict_recurse_dict");

  t_atom atom[1];

  // ==== Store the state variables on the beginning of the function
  t_bool has_match_ini = x->has_match;
  t_int32 path_len_ini = (t_int32)strlen(x->path);
  t_value_type type_iter_ini = x->type_iter;
  t_dictionary *dict_iter_ini = x->dict_iter;
  t_symbol *key_iter_ini = x->key_iter;
  
  // ==== Add :: to the path
  strncat_zero(x->path, "::", x->path_len_max);

  // ==== Get the dictionary keys
  long  key_cnt = 0;
  t_symbol **key_arr = NULL;
  dictionary_getkeys(dict, &key_cnt, &key_arr);

  // ==== Increment the depth
  depth++;

  // ==== Set the trailing variables before for the recursions
  x->type_iter = VALUE_TYPE_DICT;
  x->dict_iter = dict;

  // ==== Loop through the keys
  for (t_int32 ind = 0; ind < key_cnt; ind++) {

    x->key_iter = key_arr[ind];

    // == Opening actions depending on which command is being processed
    switch (x->command) {
    
    case CMD_FIND_KEY_IN:
    case CMD_FIND_KEY:
      if (regexpr_match(x->search_key_expr, x->key_iter)) {
        x->has_match = true; x->count++; }    // x->has_match changed
      break;

    case CMD_REPLACE_KEY:
      if (regexpr_match(x->search_key_expr, x->key_iter)) {
        dictionary_getatom(dict, x->key_iter, atom);
        dictionary_chuckentry(dict, x->key_iter);
        dictionary_appendatom(dict, x->replace_key_sym, atom);
        x->count++;

        if (x->a_verbose == true) {
          POST("  %s%s  replaced by  \"%s\"",
            x->path, x->key_iter->s_name, x->replace_key_sym->s_name); }
        x->key_iter = x->replace_key_sym; }
      break;
    
    case CMD_DELETE_KEY:
      if (regexpr_match(x->search_key_expr, x->key_iter)) {
        dictionary_deleteentry(dict, x->key_iter);
        x->count++;

        if (x->a_verbose == true) {
          POST("  %s%s  deleted",
            x->path, x->key_iter->s_name, x->replace_key_sym->s_name); }

        continue; }    // NB: No further recursion
      break;

    case CMD_REPLACE_VALUE_FROM_DICT:
      if (regexpr_match(x->search_key_expr, x->key_iter)
          && dictionary_hasentry(x->replace_dict, x->key_iter)) {

        t_symbol *key_iter[2]; key_iter[0] = x->key_iter; key_iter[1] = NULL;
        dictionary_copyentries(x->replace_dict, dict, key_iter);    // NB: Strange it does not require the array size
        x->count++;

        if (x->a_verbose == true) {
          POST("  %s%s  replaced from  \"%s\"",
            x->path, x->key_iter->s_name, x->replace_dict_sym->s_name); }

        continue; }    // NB: No further recursion
      break;
        
    default: break;
    }    // >>>> END switch through potential commands

    // == Set the trailing variables before for the recursion
    strncat_zero(x->path, x->key_iter->s_name, x->path_len_max);    // NB: x->path changed
    
    // == Get the value and recurse to it
    dictionary_getatom(dict, x->key_iter, atom);    // NB: This creates a copy
    _dict_recurse_value(x, atom, depth);
    
    // == Reset the values that changed in this loop
    x->path[path_len_ini + 2] = '\0';
    x->has_match = has_match_ini; }    // >>>> END of loop through the keys
  
  // ==== Restore the remaining state variables to their beginning values
  x->type_iter = type_iter_ini;
  x->dict_iter = dict_iter_ini;
  x->key_iter = key_iter_ini;
  
  if (key_arr) { dictionary_freekeys(dict, key_cnt, key_arr); }
}