Chapter 5. AgsAudio a container of AgsChannel

Table of Contents

AgsNotation and AgsNote
AgsAutomation and AgsAcceleration
AgsWave and AgsBuffer
AgsRecallID and AgsRecyclingContext
Dealing with recalls
Open audio files
Audio container
Audio file

AgsAudio contains a pointer to your notation and automation data. It has its own recall context, AgsRecallAudio. It organizes your recycling contices and thus having an associated AgsRecallID for running contices. Further AgsAudio is your topmost nesting level of AgsAudioSignal. You might traverse the layers in following order:

  1. AgsAudio
  2. AgsChannel
  3. AgsRecycling
  4. AgsAudioSignal

AgsAudioSignal keeps your audio data as a GList of buffers. AgsRecycling is your nested tree to AgsChannel, giving you the opportunity to emit ::add_audio_signal or ::remove_audio_signal by producer and to have many consumers. AgsChannel is your opposite to an audio channel representing a single line. AgsAudio keeps track of all of them. You might want to add your audio object to an AgsSoundcard.

You may resize the count of pads or audio channels with void ags_audio_set_pads(AgsAudio*, GType, guint, guint) and void ags_audio_set_audio_channels(AgsAudio*, guint, guint). Like in the following example the channels are adjusted and notation is added.

Example 5.1. Using AgsAudio

#include <glib.h>
#include <glib-object.h>

#include <ags/libags.h>
#include <ags/libags-audio.h>

AgsApplicationContext *application_context;
GList *soundcard;
AgsAudio *audio;
AgsNotation *notation;

guint audio_channels;
guint i;

/* get application context and soundcard */
application_context = ags_application_context_get_instance();
soundcard = ags_sound_provider_get_soundcard(AGS_SOUND_PROVIDER(application_context));

/* creat audio and resize channels */
audio_channels = 2;

audio = ags_audio_new(soundcard->data);
ags_audio_set_audio_channels(audio,
                             audio_channels);
ags_audio_set_pads(audio,
                   AGS_TYPE_OUTPUT,
                   1);
ags_audio_set_pads(audio,
                   AGS_TYPE_INPUT,
                   1);

/* add notation */
for(i = 0; i < audio_channels; i++){
  notation = ags_notation_new(audio,
                              i);
  ags_audio_add_notation(audio,
                         notation);
}

    

AgsNotation and AgsNote

AgsAudio provides many AgsNotation objects for one single audio channel. They all have a different :timestamp property. Usually a new AgsNotation object is introduced as AGS_NOTATION_DEFAULT_OFFSET is exceeded. So AgsNotation can hold at most 1024 x-positions of AgsNote.

You might want to query a GList of AgsNotation by the matching AgsTimestamp using AGS_TIMESTAMP_OFFSET.

  • void ags_notation_find_near_timestamp(GList*, guint, AgsTimestamp*)

The notation object stores your notes as a GList. You can add or remove a note by calling appropriate function:

  • void ags_notation_add_note(AgsNotation*, AgsNote*, gboolean)
  • gboolean ags_notation_remove_note_at_position(AgsNotation, guint, guint)

The notation object supports selection of notes. There are functions available to select a single point or a region of the notation. You may find specific notes by calling:

  • AgsNote* ags_notation_find_point(AgsNotation*, guint, guint, gboolean)
  • GList* ags_notation_find_region(AgsNotation*, guint, guint, guint, guint, gboolean)

To copy & paste notes you might want to select a region first. Then copy the selection and insert it using new x_offset later.

Example 5.2. Using AgsNotation Clipboard

#include <glib.h>
#include <glib-object.h>

#include <ags/libags.h>
#include <ags/libags-audio.h>

AgsAudio *audio;
AgsNotation *notation;
AgsNote *note;

xmlNode *clipboard;

guint i;

audio = ags_audio_new();

notation = ags_notation_new(audio,
			    0);
ags_audio_add_notation(audio,
		       notation);

for(i = 0; i < 16; i++){
  note = ags_note_new_with_offset(i * 4, (i * 4) + 1,
				  0);
  ags_notation_add_note(notation,
			note,
			FALSE);
}

/* select, copy & paste */
ags_notation_add_region_to_selection(notation,
				     0, 0,
				     64, 1,
				     TRUE);

clipboard = ags_notation_copy_selection(notation);
ags_notation_insert_from_clipboard(notation,
				   clipboard,
				   TRUE, 64,
				   FALSE, 0);