class_docstr: The Groove MIDI Dataset (GMD) of drum performances.
class_docstr_tok: ["The","Groove","MIDI","Dataset","(","GMD",")","of","drum","performances","."]
code: def _generate_examples(self, rows, data_dir):
      split_bars = (
          self._builder_config.split_bars
      )  # pytype: disable=attribute-error  # always-use-return-annotations
      for row in rows:
          split_genre = row["style"].split("/")
          with tf.io.gfile.GFile(
              os.path.join(data_dir, row["midi_filename"]), "rb"
          ) as midi_f:
              midi = midi_f.read()
          audio = None
          if (
              self._builder_config.include_audio
          ):  # pytype: disable=attribute-error  # always-use-return-annotations
              if not row["audio_filename"]:
                  # Skip examples with no audio.
                  logging.warning(
                      "Skipping example with no audio: %s", row["id"]
                  )
                  continue
              wav_path = os.path.join(data_dir, row["audio_filename"])
              audio = _load_wav(
                  wav_path, self._builder_config.audio_rate
              )  # pytype: disable=attribute-error  # always-use-return-annotations
  
          example = {
              "id": row["id"],
              "drummer": row["drummer"],
              "type": row["beat_type"],
              "bpm": int(row["bpm"]),
              "time_signature": row["time_signature"],
              "style": {
                  "primary": split_genre[0],
                  "secondary": split_genre[1]
                  if len(split_genre) == 2
                  else "",
              },
          }
          if not split_bars:
              # Yield full example.
              example["midi"] = midi
              if audio is not None:
                  example["audio"] = audio
              yield example["id"], example
          else:
              # Yield split examples.
              bpm = int(row["bpm"])
              beats_per_bar = int(row["time_signature"].split("-")[0])
              bar_duration = 60 / bpm * beats_per_bar
              audio_rate = (
                  self._builder_config.audio_rate
              )  # pytype: disable=attribute-error  # always-use-return-annotations
  
              pm = tfds.core.lazy_imports.pretty_midi.PrettyMIDI(
                  io.BytesIO(midi)
              )
              total_duration = pm.get_end_time()
  
              # Pad final bar if at least half filled.
              total_bars = int(round(total_duration / bar_duration))
              total_frames = int(total_bars * bar_duration * audio_rate)
              if audio is not None and len(audio) < total_frames:
                  audio = np.pad(
                      audio, [0, total_frames - len(audio)], "constant"
                  )
  
              for i in range(total_bars - split_bars + 1):
                  time_range = [
                      i * bar_duration,
                      (i + split_bars) * bar_duration,
                  ]
  
                  # Split MIDI.
                  pm_split = copy.deepcopy(pm)
                  pm_split.adjust_times(
                      time_range, [0, split_bars * bar_duration]
                  )
                  pm_split.time_signature_changes = (
                      pm.time_signature_changes
                  )
                  midi_split = io.BytesIO()
                  pm_split.write(midi_split)
                  example["midi"] = midi_split.getvalue()
  
                  # Split audio.
                  if audio is not None:
                      example["audio"] = audio[
                          int(time_range[0] * audio_rate) : int(
                              time_range[1] * audio_rate
                          )
                      ]
  
                  example["id"] += ":%03d" % i
                  yield example["id"], example
  
file_path: datasets/tensorflow_datasets/datasets/groove/groove_dataset_builder.py
imports: from __future__ import annotations
  import collections
  import copy
  import csv
  import io
  import os
  from absl import logging
  import numpy
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 3 for calling the Builder obj's underlying member method code with example usage: obj._generate_examples(rows, data_dir) without return types