class_docstr: Encode and decode events.
  
  Useful for declaring what certain ranges of a vocabulary should be used for. This is intended to be used from
  Python before encoding or after decoding with GenericTokenVocabulary. This class is more lightweight and does not
  include things like EOS or UNK token handling.
  
  To ensure that 'shift' events are always the first block of the vocab and start at 0, that event type is required
  and specified separately.
class_docstr_tok: ["Encode","and","decode","events",".","Useful","for","declaring","what","certain","ranges","of","a","vocabulary","should","be","used","for",".","This","is","intended","to","be","used","from","Python","before","encoding","or","after","decoding","with","GenericTokenVocabulary",".","This","class","is","more","lightweight","and","does","not","include","things","like","EOS","or","UNK","token","handling",".","To","ensure","that","'shift","'","events","are","always","the","first","block","of","the","vocab","and","start","at","0",",","that","event","type","is","required","and","specified","separately","."]
docstr: Encode an event to an index.
docstr_tok: ["Encode","an","event","to","an","index","."]
code: def encode_event(self, event: Event) -> int:
      """Encode an event to an index."""
      offset = 0
      for er in self._event_ranges:
          if event.type == er.type:
              if not er.min_value <= event.value <= er.max_value:
                  raise ValueError(
                      f"Event value {event.value} is not within valid range "
                      f"[{er.min_value}, {er.max_value}] for type {event.type}"
                  )
              return offset + event.value - er.min_value
          offset += er.max_value - er.min_value + 1
  
      raise ValueError(f"Unknown event type: {event.type}")
  
imports: import dataclasses
  import math
  import os
  from typing import Any, Callable, List, Mapping, MutableMapping, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  import torch.nn.functional
  from ...utils import is_note_seq_available
  from .pipeline_spectrogram_diffusion import TARGET_FEATURE_LENGTH
label_desc: Use image node_id 5 for calling the Codec obj's underlying member method code with example usage: obj.encode_event(event) and returns: unknown