3 Copyright (C) 1998-2000, Michael Pruett <michael@68k.org>
4 Copyright (C) 2000, Silicon Graphics, Inc.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this library; if not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307 USA.
25 This file contains routines for dealing with loop markers.
36 #include "audiofile.h"
37 #include "afinternal.h"
40 _Marker
*_af_marker_find_by_id (_Track
*track
, int markerid
)
46 for (i
=0; i
<track
->markerCount
; i
++)
47 if (track
->markers
[i
].id
== markerid
)
48 return &track
->markers
[i
];
50 _af_error(AF_BAD_MARKID
, "no mark with id %d found in track %d",
56 void afInitMarkIDs(AFfilesetup setup
, int trackid
, int markids
[], int nmarks
)
61 if (!_af_filesetup_ok(setup
))
64 if ((track
= _af_filesetup_get_tracksetup(setup
, trackid
)) == NULL
)
67 if (track
->markers
!= NULL
)
69 for (i
=0; i
<track
->markerCount
; i
++)
71 if (track
->markers
[i
].name
!= NULL
)
72 free(track
->markers
[i
].name
);
73 if (track
->markers
[i
].comment
!= NULL
)
74 free(track
->markers
[i
].comment
);
79 track
->markers
= _af_calloc(nmarks
, sizeof (struct _MarkerSetup
));
80 track
->markerCount
= nmarks
;
82 for (i
=0; i
<nmarks
; i
++)
84 track
->markers
[i
].id
= markids
[i
];
85 track
->markers
[i
].name
= _af_strdup("");
86 track
->markers
[i
].comment
= _af_strdup("");
89 track
->markersSet
= true;
92 void afInitMarkName(AFfilesetup setup
, int trackid
, int markid
,
98 _TrackSetup
*track
= NULL
;
103 track
= _af_filesetup_get_tracksetup(setup
, trackid
);
108 _af_error(AF_BAD_TRACKID
, "bad track id");
112 for (markno
=0; markno
<track
->markerCount
; markno
++)
114 if (track
->markers
[markno
].id
== markid
)
118 if (markno
== track
->markerCount
)
120 _af_error(AF_BAD_MARKID
, "no marker id %d for file setup", markid
);
124 length
= strlen(namestr
);
127 _af_error(AF_BAD_STRLEN
,
128 "warning: marker name truncated to 255 characters");
132 if (track
->markers
[markno
].name
)
133 free(track
->markers
[markno
].name
);
134 if ((track
->markers
[markno
].name
= _af_malloc(length
+1)) == NULL
)
136 strncpy(track
->markers
[markno
].name
, namestr
, length
);
138 The null terminator is not set by strncpy if
139 strlen(namestr) > length. Set it here.
141 track
->markers
[markno
].name
[length
] = '\0';
144 void afInitMarkComment(AFfilesetup setup
, int trackid
, int markid
,
149 _TrackSetup
*track
= NULL
;
154 track
= _af_filesetup_get_tracksetup(setup
, trackid
);
159 _af_error(AF_BAD_TRACKID
, "bad track id");
163 for (markno
=0; markno
<track
->markerCount
; markno
++)
165 if (track
->markers
[markno
].id
== markid
)
169 if (markno
== track
->markerCount
)
171 _af_error(AF_BAD_MARKID
, "no marker id %d for file setup", markid
);
175 length
= strlen(commstr
);
177 if (track
->markers
[markno
].comment
)
178 free(track
->markers
[markno
].comment
);
179 if ((track
->markers
[markno
].comment
= _af_malloc(length
+1)) == NULL
)
181 strcpy(track
->markers
[markno
].comment
, commstr
);
184 char *afGetMarkName (AFfilehandle file
, int trackid
, int markid
)
189 assert(file
!= NULL
);
192 if (!_af_filehandle_ok(file
))
195 if ((track
= _af_filehandle_get_track(file
, trackid
)) == NULL
)
198 if ((marker
= _af_marker_find_by_id(track
, markid
)) == NULL
)
204 char *afGetMarkComment (AFfilehandle file
, int trackid
, int markid
)
209 assert(file
!= NULL
);
212 if (!_af_filehandle_ok(file
))
215 if ((track
= _af_filehandle_get_track(file
, trackid
)) == NULL
)
218 if ((marker
= _af_marker_find_by_id(track
, markid
)) == NULL
)
221 return marker
->comment
;
224 void afSetMarkPosition (AFfilehandle file
, int trackid
, int markid
,
230 assert(file
!= NULL
);
233 if (!_af_filehandle_ok(file
))
236 if (!_af_filehandle_can_write(file
))
239 if ((track
= _af_filehandle_get_track(file
, trackid
)) == NULL
)
242 if ((marker
= _af_marker_find_by_id(track
, markid
)) == NULL
)
247 _af_error(AF_BAD_MARKPOS
, "invalid marker position %d", pos
);
251 marker
->position
= pos
;
254 int afGetMarkIDs (AFfilehandle file
, int trackid
, int markids
[])
260 if (!_af_filehandle_ok(file
))
263 if ((track
= _af_filehandle_get_track(file
, trackid
)) == NULL
)
270 for (i
=0; i
<track
->markerCount
; i
++)
272 markids
[i
] = track
->markers
[i
].id
;
276 return track
->markerCount
;
279 AFframecount
afGetMarkPosition (AFfilehandle file
, int trackid
, int markid
)
287 if (!_af_filehandle_ok(file
))
290 if ((track
= _af_filehandle_get_track(file
, trackid
)) == NULL
)
293 if ((marker
= _af_marker_find_by_id(track
, markid
)) == NULL
)
296 return marker
->position
;
299 _Marker
*_af_marker_new (int count
)
301 _Marker
*markers
= _af_calloc(count
, sizeof (_Marker
));