visualizer-selection: add visualizer helpers

Adds a copy helper (for thread access) and a contains helper.
This commit is contained in:
Christian Hergert
2016-10-08 19:19:46 -07:00
parent 7c55f379bb
commit 42b82f69c9
2 changed files with 43 additions and 2 deletions

View File

@ -212,3 +212,40 @@ sp_visualizer_selection_unselect_all (SpVisualizerSelection *self)
g_signal_emit (self, signals [CHANGED], 0);
}
}
gboolean
sp_visualizer_selection_contains (SpVisualizerSelection *self,
gint64 time_at)
{
if (self == NULL || self->ranges->len == 0)
return TRUE;
for (guint i = 0; i < self->ranges->len; i++)
{
const Range *range = &g_array_index (self->ranges, Range, i);
if (time_at >= range->begin && time_at <= range->end)
return TRUE;
}
return FALSE;
}
SpVisualizerSelection *
sp_visualizer_selection_copy (const SpVisualizerSelection *self)
{
SpVisualizerSelection *copy;
if (self == NULL)
return NULL;
copy = g_object_new (SP_TYPE_VISUALIZER_SELECTION, NULL);
for (guint i = 0; i < self->ranges->len; i++)
{
Range range = g_array_index (self->ranges, Range, i);
g_array_append_val (copy->ranges, range);
}
return copy;
}