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 All routines that operate on loops.
32 #include "audiofile.h"
33 #include "afinternal.h"
36 #include "instrument.h"
38 void afInitLoopIDs (AFfilesetup setup
, int instid
, int *loopids
, int nloops
)
42 if (!_af_filesetup_ok(setup
))
45 if (!_af_unique_ids(loopids
, nloops
, "loop", AF_BAD_LOOPID
))
48 if ((instno
= _af_setup_instrument_index_from_id(setup
, instid
)) == -1)
51 _af_setup_free_loops(setup
, instno
);
53 setup
->instruments
[instno
].loopCount
= nloops
;
54 setup
->instruments
[instno
].loopSet
= true;
57 setup
->instruments
[instno
].loops
= NULL
;
62 if ((setup
->instruments
[instno
].loops
= _af_calloc(nloops
, sizeof (_LoopSetup
))) == NULL
)
65 for (i
=0; i
< nloops
; i
++)
66 setup
->instruments
[instno
].loops
[i
].id
= loopids
[i
];
70 int afGetLoopIDs (AFfilehandle file
, int instid
, int *loopids
)
75 if (!_af_filehandle_ok(file
))
78 if ((instno
= _af_handle_instrument_index_from_id(file
, instid
)) == -1)
82 for (i
=0; i
< file
->instruments
[instno
].loopCount
; i
++)
83 loopids
[i
] = file
->instruments
[instno
].loops
[i
].id
;
85 return file
->instruments
[instno
].loopCount
;
88 int _af_handle_loop_index_from_id (AFfilehandle file
, int instno
, int loopid
)
91 for (i
=0; i
<file
->instruments
[instno
].loopCount
; i
++)
92 if (file
->instruments
[instno
].loops
[i
].id
== loopid
)
95 _af_error(AF_BAD_LOOPID
, "no loop with id %d for instrument %d",
96 loopid
, file
->instruments
[instno
].id
);
102 getLoop returns pointer to requested loop if it exists, and if
103 mustWrite is true, only if handle is writable.
106 static _Loop
*getLoop (AFfilehandle handle
, int instid
, int loopid
,
111 if (!_af_filehandle_ok(handle
))
114 if (mustWrite
&& !_af_filehandle_can_write(handle
))
117 if ((instno
= _af_handle_instrument_index_from_id(handle
, instid
)) == -1)
120 if ((loopno
= _af_handle_loop_index_from_id(handle
, instno
, loopid
)) == -1)
123 return &handle
->instruments
[instno
].loops
[loopno
];
127 Set loop mode (as in AF_LOOP_MODE_...).
129 void afSetLoopMode (AFfilehandle file
, int instid
, int loopid
, int mode
)
131 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
136 if (mode
!= AF_LOOP_MODE_NOLOOP
&&
137 mode
!= AF_LOOP_MODE_FORW
&&
138 mode
!= AF_LOOP_MODE_FORWBAKW
)
140 _af_error(AF_BAD_LOOPMODE
, "unrecognized loop mode %d", mode
);
148 Get loop mode (as in AF_LOOP_MODE_...).
150 int afGetLoopMode (AFfilehandle file
, int instid
, int loopid
)
152 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
163 int afSetLoopCount (AFfilehandle file
, int instid
, int loopid
, int count
)
165 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
172 _af_error(AF_BAD_LOOPCOUNT
, "invalid loop count: %d", count
);
183 int afGetLoopCount(AFfilehandle file
, int instid
, int loopid
)
185 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
194 Set loop start marker id in the file structure
197 afSetLoopStart(AFfilehandle file
, int instid
, int loopid
, int markid
)
199 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
204 loop
->beginMarker
= markid
;
208 Get loop start marker id.
210 int afGetLoopStart (AFfilehandle file
, int instid
, int loopid
)
212 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
217 return loop
->beginMarker
;
221 Set loop start frame in the file structure.
223 int afSetLoopStartFrame (AFfilehandle file
, int instid
, int loopid
, AFframecount startFrame
)
225 int trackid
, beginMarker
;
226 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
233 _af_error(AF_BAD_FRAME
, "loop start frame must not be negative");
237 trackid
= loop
->trackid
;
238 beginMarker
= loop
->beginMarker
;
240 afSetMarkPosition(file
, trackid
, beginMarker
, startFrame
);
245 Get loop start frame.
247 AFframecount
afGetLoopStartFrame (AFfilehandle file
, int instid
, int loopid
)
249 int trackid
, beginMarker
;
250 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
255 trackid
= loop
->trackid
;
256 beginMarker
= loop
->beginMarker
;
258 return afGetMarkPosition(file
, trackid
, beginMarker
);
264 void afSetLoopTrack (AFfilehandle file
, int instid
, int loopid
, int track
)
266 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
270 loop
->trackid
= track
;
276 int afGetLoopTrack (AFfilehandle file
, int instid
, int loopid
)
278 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
283 return loop
->trackid
;
287 Set loop end frame marker id.
289 void afSetLoopEnd (AFfilehandle file
, int instid
, int loopid
, int markid
)
291 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
296 loop
->endMarker
= markid
;
300 Get loop end frame marker id.
302 int afGetLoopEnd (AFfilehandle file
, int instid
, int loopid
)
304 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
309 return loop
->endMarker
;
315 int afSetLoopEndFrame (AFfilehandle file
, int instid
, int loopid
, AFframecount endFrame
)
317 int trackid
, endMarker
;
318 _Loop
*loop
= getLoop(file
, instid
, loopid
, true);
325 _af_error(AF_BAD_FRAME
, "loop end frame must not be negative");
329 trackid
= loop
->trackid
;
330 endMarker
= loop
->endMarker
;
332 afSetMarkPosition(file
, trackid
, endMarker
, endFrame
);
340 AFframecount
afGetLoopEndFrame (AFfilehandle file
, int instid
, int loopid
)
342 int trackid
, endMarker
;
343 _Loop
*loop
= getLoop(file
, instid
, loopid
, false);
348 trackid
= loop
->trackid
;
349 endMarker
= loop
->endMarker
;
351 return afGetMarkPosition(file
, trackid
, endMarker
);