code: def note_event_data_to_events(
      state: Optional[NoteEncodingState],
      value: NoteEventData,
      codec: Codec,
  ) -> Sequence[Event]:
      """Convert note event data to a sequence of events."""
      if value.velocity is None:
          # onsets only, no program or velocity
          return [Event("pitch", value.pitch)]
      else:
          num_velocity_bins = num_velocity_bins_from_codec(codec)
          velocity_bin = velocity_to_bin(
              value.velocity, num_velocity_bins
          )
          if value.program is None:
              # onsets + offsets + velocities only, no programs
              if state is not None:
                  state.active_pitches[(value.pitch, 0)] = velocity_bin
              return [
                  Event("velocity", velocity_bin),
                  Event("pitch", value.pitch),
              ]
          else:
              if value.is_drum:
                  # drum events use a separate vocabulary
                  return [
                      Event("velocity", velocity_bin),
                      Event("drum", value.pitch),
                  ]
              else:
                  # program + velocity + pitch
                  if state is not None:
                      state.active_pitches[
                          (value.pitch, value.program)
                      ] = velocity_bin
                  return [
                      Event("program", value.program),
                      Event("velocity", velocity_bin),
                      Event("pitch", value.pitch),
                  ]
  
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 10 for calling a global function with example usage: note_event_data_to_events(state, value, codec) and returns: list, list, list, list