def saveSequenceEvents(events, notableEvents=None):
    """
    Convert a list of SequenceEvent objects to raw sequence event data.
    This is the inverse of readSequenceEvents().

    A second list will also be returned that contains the offsets in the
    output data of the elements from notableEvents.
    """
    if notableEvents is None:
        notableEvents = []
    events2Offsets = {}
    off = 0
    for e in events:
        events2Offsets[e] = off
        off += e.dataLength
    data = bytearray(off)
    for event, offset in events2Offsets.items():
        eData = event.save(events2Offsets)
        data[offset:offset + len(eData)] = eData
    notableOffsets = [events2Offsets[e] for e in notableEvents]
    return data, notableOffsets
