Advanced Gtk+ Sequencer

This page describes how code should be formated contributing to Advanced Gtk+ Sequencer.

Macros

Macro names are lower-case.

#ifdef AGS_WITH_ALSA

...

#endif      

C macros are generally upper-case and prefixed with AGS_*.

#define AGS_USEC_PER_SEC (1000000)

You may want to split a macro representing on multiple lines.

#define AGS_TURTLE_UTF8_RANGE_0 "([A-Za-z])"
#define AGS_TURTLE_UTF8_RANGE_1 "(\xC3[\x80-\x96])"

#define AGS_TURTLE_UTF8_RANGE_ALL "(" AGS_TURTLE_UTF8_RANGE_0 "|" \
  AGS_TURTLE_UTF8_RANGE_1

Use parenthesis around terms and type casts.

#define AGS_EDITOR_CHILD(ptr) ((AgsEditorChild *)(ptr))

Variables

All variables are lower-case and have a meaningful naming you may want to use underscores to separate words. Avoid global variables for a singleton you shall prefix it with ags_*. Don't make global variables static. Only global and static variables are initialized during declaration. How ever it is prefered to not do so and use a condition to do so.

AgsApplicationContext *ags_application_context = NULL;

Conditions

Always use brackets even when you might want to ommit. An if condition might look like:

if(automation->audio == (GObject *) audio){
  return;
}

The switch condition might look like:

switch(ags_format){
case AGS_SOUNDCARD_SIGNED_8_BIT:
  {
    res = (int) ((signed char *) buffer)[count * channels + chn];
  }
  break;
case AGS_SOUNDCARD_SIGNED_16_BIT:
  {
    res = (int) ((signed short *) buffer)[count * channels + chn];
  }
  break;
case AGS_SOUNDCARD_SIGNED_24_BIT:
  {
    res = (int) ((signed long *) buffer)[count * channels + chn];
  }
  break;
case AGS_SOUNDCARD_SIGNED_32_BIT:
  {
    res = (int) ((signed long *) buffer)[count * channels + chn];
  }
  break;
}

Loops

Don't do extra white-spaces between brackets. Only the one needed for readability. A for-loop might look as following:

for(i = 0; i < length; i++){
  recycling_context->recycling[i] = NULL;
}

So do the the while-loop.

while(current != NULL){
  g_object_set(G_OBJECT(current->data),
               "soundcard\0", soundcard,
               NULL);

  current = current->next;
}

And finally the do-while-loop:

do{
  notes_next = notes->next;

  if(note->y == y){
    if(notes->prev != NULL){
      notes->prev->next = notes->next;
    }

    if(notes->next != NULL){
      notes->next->prev = notes->prev;
    }

    if(notation->notes == notes){
      notation->notes = notes->next;
    }

    notes->prev = NULL;
    notes->next = NULL;
    g_list_free_1(notes);

    g_object_unref(note);

    return(TRUE);
  } 

  notes = notes_next;
}while(notes != NULL &&
       (note = AGS_NOTE(notes->data))->x[0] == x &&
       note->y <= y);

Functions

Funtions are always declared either in header file as public or within .c file as private.

void ags_audio_open_files(AgsAudio *audio,
                          GSList *filenames,
                          gboolean overwrite_channels,
                          gboolean create_channels);

Implemented as:

void
ags_audio_open_files(AgsAudio *audio,
                     GSList *filenames,
                     gboolean overwrite_channels,
                     gboolean create_channels)
{
  ...
}

Nested functions are declared like following:

auto void ags_audio_set_audio_channels_init_parameters(GType type);

Implemented as:

void ags_audio_set_audio_channels_init_parameters(GType type){
  ...
}

Headers

Header files are always protected of multiple-include by following:

/* GSequencer - Advanced GTK Sequencer
 * Copyright (C) 2005-2015 Joël Krähemann
 *
 * This file is part of GSequencer.
 *
 * GSequencer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GSequencer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GSequencer.  If not, see .
 */
#ifndef __AGS_ID_GENERATOR_H__
#define __AGS_ID_GENERATOR_H__

#include <glib.h>

gchar* ags_id_generator_create_uuid();

#endif /*__AGS_ID_GENERATOR_H__*/	

C source file

First includes, then private declarations, gtk-doc comment and finally global variables. Afterwards, following implementations

/* GSequencer - Advanced GTK Sequencer
 * Copyright (C) 2005-2015 Joël Krähemann
 *
 * This file is part of GSequencer.
 *
 * GSequencer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GSequencer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GSequencer.  If not, see .
 */
#include <ags/lib/ags_turtle_manager.h>
#include <ags/lib/ags_turtle.h>

void ags_turtle_manager_class_init(AgsTurtleManagerClass *turtle_manager);
void ags_turtle_manager_init (AgsTurtleManager *turtle_manager);
void ags_turtle_manager_finalize(GObject *gobject);

/**
 * SECTION:ags_turtle_manager
 * @short_description: Singleton pattern to organize turtles
 * @title: AgsTurtleManager
 * @section_id:
 * @include: ags/object/ags_turtle_manager.h
 *
 * The #AgsTurtleManager keeps track of your turtles.
 */

static gpointer ags_turtle_manager_parent_class = NULL;

AgsTurtleManager *ags_turtle_manager = NULL;

Last modified: Mon Jun 17:57:18 UTC 2017 by joelkraehemann