function [ tdelta, event ] = get_event_by_frame (self, tag, frame, direction)
    % event = GET_EVENT_BY_FRAME (self, tag, frame, direction)
    %
    % Retrieves event for TAG in the frame specified by FRAME. The
    % function internally converts the frame number into timestamp and
    % retrieves the event.
    %
    % Input:
    %  - self = @UbisenseDatabase instance
    %  - tag = tag ID, either in integer or in string form
    %  - frame = frame number
    %  - direction = specifies the direction in which to search for the
    %    event, relative to the time instant corresponding to FRAME:
    %    - 'next' = next event
    %    - 'prev' = previous event
    %    - 'closest' = choose the closest event from next and previous
    %      events
    %
    % Output:
    %  - event = event for the specified tag in specified frame
    %  - tdelta = deviation from the timestamp associated with the
    %    specified frame
    %
    % Copyright (C) 2011-2012, Rok Mandeljc <rok.mandeljc@fe.uni-lj.si>
    
    % Default parameter for direction is 'prev' (zero-hold behavior)
    if nargin < 4,
        direction = 'prev';
    end
    
    % Get event by timestamp
    timestamp = self.timestamp.get_timestamp(frame, false);
    [ tdelta, event ] = self.get_event_by_timestamp(tag, timestamp, direction);
end