code: def mix_sequences(
      individual_samples, sample_rate, individual_sequences
  ):
      """Mix multiple audio/notesequence pairs together.
  
      All sequences will be repeated until they are as long as the longest sequence.
  
      Note that the mixed sequence will contain only the (sustain-processed) notes
      from the individual sequences. All other control changes and metadata will not
      be preserved.
  
      Args:
        individual_samples: A list of audio samples to mix.
        sample_rate: Rate at which to interpret the samples
        individual_sequences: A list of NoteSequences to mix.
  
      Returns:
        mixed_samples: The mixed audio.
        mixed_sequence: The mixed NoteSequence.
      """
      # Normalize samples and sequence velocities before mixing.
      # This ensures that the velocities/loudness of the individual samples
      # are treated equally.
      for i, samples in enumerate(individual_samples):
          individual_samples[i] = librosa.util.normalize(
              samples, norm=np.inf
          )
      for sequence in individual_sequences:
          velocities = [note.velocity for note in sequence.notes]
          velocity_max = np.max(velocities)
          for note in sequence.notes:
              note.velocity = int(
                  (note.velocity / velocity_max)
                  * constants.MAX_MIDI_VELOCITY
              )
  
      # Ensure that samples are always at least as long as their paired sequences.
      for i, (samples, sequence) in enumerate(
          zip(individual_samples, individual_sequences)
      ):
          if len(samples) / sample_rate < sequence.total_time:
              padding = int(
                  math.ceil(
                      (sequence.total_time - len(samples) / sample_rate)
                      * sample_rate
                  )
              )
              individual_samples[i] = np.pad(
                  samples, [0, padding], "constant"
              )
  
      # Repeat each ns/wav pair to be as long as the longest wav.
      max_duration = (
          np.max([len(s) for s in individual_samples]) / sample_rate
      )
  
      extended_samples = []
      extended_sequences = []
      for samples, sequence in zip(
          individual_samples, individual_sequences
      ):
          extended_samples.append(
              audio_io.repeat_samples_to_duration(
                  samples, sample_rate, max_duration
              )
          )
          extended_sequences.append(
              sequences_lib.repeat_sequence_to_duration(
                  sequence,
                  max_duration,
                  sequence_duration=len(samples) / sample_rate,
              )
          )
  
      # Mix samples and sequences together
      mixed_samples = np.zeros_like(extended_samples[0])
      for samples in extended_samples:
          mixed_samples += samples / len(extended_samples)
  
      mixed_sequence = music_pb2.NoteSequence()
      mixed_sequence.ticks_per_quarter = constants.STANDARD_PPQ
      del mixed_sequence.notes[:]
      for sequence in extended_sequences:
          # Process sustain changes before copying notes.
          sus_sequence = sequences_lib.apply_sustain_control_changes(
              sequence
          )
          if sus_sequence.total_time > mixed_sequence.total_time:
              mixed_sequence.total_time = sus_sequence.total_time
          # TODO(fjord): Manage instrument/program numbers.
          mixed_sequence.notes.extend(sus_sequence.notes)
  
      return mixed_samples, mixed_sequence
  
file_path: magenta/magenta/models/onsets_frames_transcription/audio_label_data_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import bisect
  import math
  import librosa
  from note_seq import audio_io
  from note_seq import constants
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 7 for calling a global function with example usage: mix_sequences(individual_samples, sample_rate, individual_sequences) and returns: mixed_samples,  mixed_sequence