3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public License
5 * as published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the Free
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 /* this file originally taken from FluidSynth - A Software Synthesizer
20 * Copyright (C) 2003 Peter Hanappe and others.
24 #include "aubio_priv.h"
26 #include "midi_event.h"
27 #include "midi_track.h"
28 #include "midi_player.h"
31 /** new_aubio_track */
32 aubio_track_t* new_aubio_track(int num)
35 track = AUBIO_NEW(aubio_track_t);
48 /** del_aubio_track */
49 int del_aubio_track(aubio_track_t* track)
51 if (track->name != NULL) {
52 AUBIO_FREE(track->name);
54 if (track->first != NULL) {
55 del_aubio_midi_event(track->first);
61 /** aubio_track_set_name */
62 int aubio_track_set_name(aubio_track_t* track, char* name)
65 if (track->name != NULL) {
66 AUBIO_FREE(track->name);
72 len = AUBIO_STRLEN(name);
73 track->name = AUBIO_MALLOC(len + 1);
74 if (track->name == NULL) {
75 AUBIO_ERR( "Out of memory");
78 AUBIO_STRCPY(track->name, name);
82 /** aubio_track_get_name */
83 char* aubio_track_get_name(aubio_track_t* track)
88 /** aubio_track_get_duration */
89 int aubio_track_get_duration(aubio_track_t* track)
92 aubio_midi_event_t* evt = track->first;
100 /** aubio_track_count_events */
101 int aubio_track_count_events(aubio_track_t* track, int* on, int* off)
103 aubio_midi_event_t* evt = track->first;
104 while (evt != NULL) {
105 if (evt->type == NOTE_ON) {
107 } else if (evt->type == NOTE_OFF) {
116 * aubio_track_add_event
118 int aubio_track_add_event(aubio_track_t* track, aubio_midi_event_t* evt)
121 if (track->first == NULL) {
126 track->last->next = evt;
133 * aubio_track_first_event
135 aubio_midi_event_t* aubio_track_first_event(aubio_track_t* track)
137 track->cur = track->first;
142 * aubio_track_next_event
144 aubio_midi_event_t* aubio_track_next_event(aubio_track_t* track)
146 if (track->cur != NULL) {
147 track->cur = track->cur->next;
156 aubio_track_reset(aubio_track_t* track)
159 track->cur = track->first;