Example #1
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;
}
Example #2
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;
}
Example #3
0
/**
Called by _dict_recurse_dict() for each entry and _dict_recurse_array() for each index
*/
t_int32 _dict_recurse_value(t_dict_recurse *x, t_atom *value, t_int32 depth)
{
  TRACE("_dict_recurse_value");

  long type = atom_gettype(value);

  // ====  INT  ====
  if (type == A_LONG) {
    snprintf_zero(x->str_tmp, MAX_LEN_NUMBER, "%i", atom_getlong(value));
    _dict_recurse_value_find(x, value, x->str_tmp); }

  // ====  FLOAT  ====
  else if (type == A_FLOAT) {
    snprintf_zero(x->str_tmp, MAX_LEN_NUMBER, "%i", atom_getfloat(value));
    _dict_recurse_value_find(x, value, x->str_tmp); }
    
  // ====  SYMBOL / STRING  ====
  // NB: values in arrays are not A_SYM but A_OBJ 
  else if ((type == A_SYM) || atomisstring(value)) {

    t_symbol *value_sym = atom_getsym(value);

    switch (x->command) {
    
    // == FIND A SYMBOL VALUE
    case CMD_FIND_VALUE_SYM:

      if (regexpr_match(x->search_val_expr, value_sym)) {
        POST("  %s  \"%s\"", x->path, value_sym->s_name); x->count++; }
      break;

    // == FIND AN ENTRY
    case CMD_FIND_ENTRY:

      if (regexpr_match(x->search_key_expr, x->key_iter)
          && regexpr_match(x->search_val_expr, value_sym)
          && (x->type_iter == VALUE_TYPE_DICT)) {

        POST("  %s  \"%s\"", x->path, value_sym->s_name); x->count++; }
      break;

    // == REPLACE A SYMBOL VALUE
    case CMD_REPLACE_VALUE_SYM:
      
      if (regexpr_match(x->search_val_expr, value_sym)) {

        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_chuckentry(x->dict_iter, x->key_iter);
          dictionary_appendsym(x->dict_iter, x->key_iter, x->replace_val_sym); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) { atom_setsym(value, x->replace_val_sym); }

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  replaced by  \"%s\"",
            x->path, value_sym->s_name, x->replace_val_sym->s_name); } }
      break;

    // == REPLACE AN ENTRY
    case CMD_REPLACE_ENTRY:
      
      if (regexpr_match(x->search_key_expr, x->key_iter)
          && regexpr_match(x->search_val_expr, value_sym)
          && (x->type_iter == VALUE_TYPE_DICT)) {

        dictionary_chuckentry(x->dict_iter, x->key_iter);
        dictionary_appendsym(x->dict_iter, x->replace_key_sym, x->replace_val_sym);

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  replaced by  (%s : %s)",
            x->path, value_sym->s_name, x->replace_key_sym->s_name, x->replace_val_sym->s_name); } }
      break;

    // == DELETE A SYMBOL VALUE
    case CMD_DELETE_VALUE_SYM:

      if (regexpr_match(x->search_val_expr, value_sym)) {

        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_deleteentry(x->dict_iter, x->key_iter); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) {
          atomarray_chuckindex(x->array_iter, x->index_iter); }

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  deleted",
            x->path, value_sym->s_name); }
        return VALUE_DEL; }
      break;

    // == DELETE A SYMBOL VALUE
    case CMD_DELETE_ENTRY:

      if (regexpr_match(x->search_key_expr, x->key_iter)
          && regexpr_match(x->search_val_expr, value_sym)
          && (x->type_iter == VALUE_TYPE_DICT)) {

        dictionary_deleteentry(x->dict_iter, x->key_iter);

        x->count++;
        if (x->a_verbose) {
          POST("  %s  \"%s\"  deleted",
            x->path, value_sym->s_name); }
        return VALUE_DEL; }
      break;

    // == DEFAULT: CMD_FIND_KEY or CMD_FIND_KEY_IN
    default:
      snprintf_zero(x->str_tmp, MAX_LEN_NUMBER, "\"%s\"", atom_getsym(value)->s_name);
      _dict_recurse_value_find(x, value, x->str_tmp);
      break; } }

  // ====  DICTIONARY  ====
  else if (atomisdictionary(value)) {

    t_dictionary *sub_dict = (t_dictionary *)atom_getobj(value);
    t_symbol *key_match = gensym("");
    t_symbol *value_match = gensym("");

    switch (x->command) {

    case CMD_FIND_DICT_CONT_ENTRY:
      
      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        x->count++;
        POST("  %s:  dict containing  (%s : %s)",
          x->path, key_match->s_name, value_match->s_name); }
      break;

    case CMD_REPLACE_DICT_CONT_ENTRY:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        t_dictionary *dict_cpy = dictionary_new();
        dictionary_clone_to_existing(x->replace_dict, dict_cpy);
        
        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_deleteentry(x->dict_iter, x->key_iter);
          dictionary_appenddictionary(x->dict_iter, x->key_iter, (t_object *)dict_cpy); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) {
          long array_len;
          t_atom *atom_arr;
          atomarray_getatoms(x->array_iter, &array_len, &atom_arr);
          atom_setobj(atom_arr + x->index_iter, dict_cpy); } 

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  replaced by  \"%s\"",
            x->path, key_match->s_name, value_match->s_name, x->replace_dict_sym->s_name); } 
      
        return VALUE_NO_DEL; }
      break;

    case CMD_DELETE_DICT_CONT_ENTRY:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        // If the value is from a dictionary entry
        if (x->type_iter == VALUE_TYPE_DICT) {
          dictionary_deleteentry(x->dict_iter, x->key_iter); }

        // If the value is from an array
        else if (x->type_iter == VALUE_TYPE_ARRAY) {
          atomarray_chuckindex(x->array_iter, x->index_iter);
          object_free(sub_dict); } 

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  deleted",
            x->path, key_match->s_name, value_match->s_name); }

        return VALUE_DEL; }
      break;

    case CMD_APPEND_IN_DICT_CONT_ENTRY:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)) {

        dictionary_appendsym(sub_dict, x->replace_key_sym, x->replace_val_sym);

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  appended  (%s : %s)",
            x->path, key_match->s_name, value_match->s_name, x->replace_key_sym->s_name, x->replace_val_sym->s_name); } }
      break;

    case CMD_APPEND_IN_DICT_CONT_ENTRY_D:

      if (_dict_recurse_match_dict(x, sub_dict, &key_match, &value_match)
          && dictionary_hasentry(x->replace_dict, x->replace_key_sym)) {

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

        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict containing  (%s : %s):  appended entry  (%s : ...)  from \"%s\"",
            x->path, key_match->s_name, value_match->s_name, x->replace_key_sym->s_name, x->replace_dict_sym->s_name); } }
      break;

    case CMD_APPEND_IN_DICT_FROM_KEY:

      if (regexpr_match(x->search_key_expr, x->key_iter)
          && (x->type_iter == VALUE_TYPE_DICT)
          && dictionary_hasentry(x->replace_dict, x->replace_key_sym)) {

        t_symbol *key[2]; key[0] = x->replace_key_sym; key[1] = NULL;
        dictionary_copyentries(x->replace_dict, sub_dict, key);    // NB: Strange it does not require the array size
        
        x->count++;
        if (x->a_verbose) {
          POST("  %s:  dict value:  appended entry  (%s : ...)  from \"%s\"",
            x->path, x->replace_key_sym->s_name, x->replace_dict_sym->s_name); } }
      break;
    
    default:
      _dict_recurse_value_find(x, value, "_DICT_"); }    // End of command "switch ..."

    _dict_recurse_dict(x, sub_dict, depth); }    // End of dictionary "else if ..."

  // ====  ARRAY  ====
  else if (atomisatomarray(value)) {

    _dict_recurse_value_find(x, value, "_ARRAY_");

    t_atomarray *atomarray = (t_atomarray *)atom_getobj(value);
    _dict_recurse_array(x, atomarray, depth);  }

  return VALUE_NO_DEL;
}
Example #4
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);
        }
    }
}
Example #5
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); }
}