+typedef enum
+{
+ westley_existing,
+ westley_producer,
+ westley_multitrack,
+ westley_playlist,
+ westley_tractor,
+ westley_filter,
+ westley_transition
+}
+westley_type;
+
+/** Create or retrieve an id associated to this service.
+*/
+
+static char *westley_get_id( serialise_context context, mlt_service service, westley_type type )
+{
+ char *id = NULL;
+ int i = 0;
+ mlt_properties map = context->id_map;
+
+ // Search the map for the service
+ for ( i = 0; i < mlt_properties_count( map ); i ++ )
+ if ( mlt_properties_get_data_at( map, i, NULL ) == service )
+ break;
+
+ // If the service is not in the map, and the type indicates a new id is needed...
+ if ( i >= mlt_properties_count( map ) && type != westley_existing )
+ {
+ // Attempt to reuse existing id
+ id = mlt_properties_get( mlt_service_properties( service ), "id" );
+
+ // If no id, or the id is used in the map (for another service), then
+ // create a new one.
+ if ( id == NULL || mlt_properties_get_data( map, id, NULL ) != NULL )
+ {
+ char temp[ ID_SIZE ];
+ do
+ {
+ switch( type )
+ {
+ case westley_producer:
+ sprintf( temp, "producer%d", context->producer_count ++ );
+ break;
+ case westley_multitrack:
+ sprintf( temp, "multitrack%d", context->multitrack_count ++ );
+ break;
+ case westley_playlist:
+ sprintf( temp, "playlist%d", context->playlist_count ++ );
+ break;
+ case westley_tractor:
+ sprintf( temp, "tractor%d", context->tractor_count ++ );
+ break;
+ case westley_filter:
+ sprintf( temp, "filter%d", context->filter_count ++ );
+ break;
+ case westley_transition:
+ sprintf( temp, "transition%d", context->transition_count ++ );
+ break;
+ case westley_existing:
+ // Never gets here
+ break;
+ }
+ }
+ while( mlt_properties_get_data( map, temp, NULL ) != NULL );
+
+ // Set the data at the generated name
+ mlt_properties_set_data( map, temp, service, 0, NULL, NULL );
+
+ // Get the pointer to the name (i is the end of the list)
+ id = mlt_properties_get_name( map, i );
+ }
+ else
+ {
+ // Store the existing id in the map
+ mlt_properties_set_data( map, id, service, 0, NULL, NULL );
+ }
+ }
+ else if ( type == westley_existing )
+ {
+ id = mlt_properties_get_name( map, i );
+ }
+
+ return id;
+}
+