예제 #1
0
파일: time_cache.cpp 프로젝트: timn/fawkes
bool
TimeCache::insert_data(const TransformStorage& new_data)
{
  L_TransformStorage::iterator storage_it = storage_.begin();

  if(storage_it != storage_.end()) {
    if (storage_it->stamp > new_data.stamp + max_storage_time_) {
      return false;
    }
  }


  while(storage_it != storage_.end()) {
    if (storage_it->stamp <= new_data.stamp)
      break;
    storage_it++;
  }
  storage_.insert(storage_it, new_data);

  prune_list();
  return true;
}
예제 #2
0
/**
 * Allocate_xes - allocate the x position for all chord elements
 * in the score(??? JUl 2011, it appears to be just a single "block" it is called for each "block")
 *
 * @param block_start_obj_nodes pointer to the starting object node
 * @param block_end_obj_nodes pointer to the last object node
 * @param num_staffs the number of staffs in the score
 * @param furthest_tick_advance
 * @param base_x
 * @param base_tick
 * @param shortest_chord_duration
 * @param shortest_chord_pixels
 * @param whole_note_width
 * @param non_chords
 *
 */
static void
allocate_xes (objnode ** block_start_obj_nodes, objnode ** block_end_obj_nodes, gint num_staffs, gint furthest_tick_advance, gint * base_x, gint * base_tick, gint shortest_chord_duration, gint shortest_chord_pixels, gint whole_note_width, GList * non_chords)
{
  gint ticks_in_block, shortest_chords_in_block, block_width, starts_at_tick;
  gint extra_advance = 0, non_chord_pixels, i;
  objnode *this_staff_obj_node;
  DenemoObject *curobj = 0;
  GList *non_chords_node = 0;

  /* Initializey stuff */
  non_chords = prune_list (non_chords);

  /* Set the block width */

  ticks_in_block = furthest_tick_advance - *base_tick;
  shortest_chords_in_block = (ticks_in_block % shortest_chord_duration)
    ? (ticks_in_block / shortest_chord_duration + 1)
    : (ticks_in_block / shortest_chord_duration);
  block_width = MAX (shortest_chords_in_block * shortest_chord_pixels, ticks_in_block * whole_note_width / WHOLE_NUMTICKS);

  /* Now go through staff-by-staff and set the xes within the block
   * only.  This code would be simpler if each mudela object stored its
   * own starttick rather that only that of its possibly hypothetical
   * successor */
  for (i = 0; i < num_staffs; i++)
    {
      this_staff_obj_node = block_start_obj_nodes[i];
      if (this_staff_obj_node)
        {
          starts_at_tick = *base_tick;
          non_chords_node = non_chords;
          extra_advance = 0;
          non_chord_pixels = 0; // if there are two non-chords in succession the minpixelsalloted is used
          while (this_staff_obj_node)
            {
              curobj = (DenemoObject *) this_staff_obj_node->data;

              while (non_chords_node && !CHORDTEST (this_staff_obj_node) && (starts_at_tick >= ((list_info *) non_chords_node->data)->start_position))
                {
                  extra_advance += ((list_info *) non_chords_node->data)->pixels;
                  non_chords_node = non_chords_node->next;
                }
              if (CHORDTEST (this_staff_obj_node))
                {
                  curobj->x = *base_x + extra_advance + non_chord_pixels + ((starts_at_tick - *base_tick) * block_width / (ticks_in_block ? ticks_in_block : 1));
                  non_chord_pixels += curobj->minpixelsalloted;
                }
              else
                {
                  curobj->x = *base_x + extra_advance + ((starts_at_tick - *base_tick) * block_width / (ticks_in_block ? ticks_in_block : 1));
                  non_chord_pixels = 0;
                }
              starts_at_tick = curobj->starttickofnextnote;

              if (this_staff_obj_node == block_end_obj_nodes[i])
                break;
              else
                this_staff_obj_node = this_staff_obj_node->next;
            }
        }
    }

  /* This while loop takes care of any more additions needed to
   * extra_advance still outstanding */

  while (non_chords_node)
    {
      extra_advance += ((list_info *) non_chords_node->data)->pixels;
      non_chords_node = non_chords_node->next;
    }

  /* Now increase the values of *base_x and *base_tick as a side-effect. */

  *base_x += block_width + extra_advance;
  *base_tick = furthest_tick_advance;   //this is growing....
  //g_debug("furthest %d\n", furthest_tick_advance);
  /* Free non_chords and we're done */

  g_list_foreach (non_chords, freeit, NULL);
  g_list_free (non_chords);
}