1 /* Copyright 2000 Kjetil S. Matheussen
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; either version 2
6 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "nsmtracker.h"
25 #include "trackreallines_proc.h"
26 #include "fxlines_proc.h"
27 #include "temponodes_proc.h"
30 #include "trackreallineelements_proc.h"
32 #define NUM_TREINHOLDER 40000
34 bool collectTREgarbage
=false; // Variable for main.
37 struct TREelementHolder
{
38 struct TREelementHolder
*next
;
40 struct TrackReallineElements tre
[NUM_TREINHOLDER
];
43 struct TrackReallineElements
*nextfreeelement
=NULL
;
45 extern size_t allocated
;
48 void ReturnRTEelement(struct TrackReallineElements
*tre
){
49 tre
->next
=nextfreeelement
;
55 void FreeAllRTEelements_fromroot(
56 struct TrackReallineElements
**to
58 struct TrackReallineElements
*rte
=*to
;
59 struct TrackReallineElements
*temp
;
63 for(;rte
!=NULL
;temp
=rte
,rte
=rte
->next
);
65 temp
->next
=nextfreeelement
;
72 ReturnRTEelement(rte
);
80 void FreeAllRTEelements_fromroot(
81 struct TrackReallineElements
**to
83 struct TrackReallineElements
*rte
= *to
;
84 struct TrackReallineElements
*temp
;
88 ReturnRTEelement(rte
);
97 void SetNextsInATreElementHolder(struct TREelementHolder
*treholder
){
98 struct TrackReallineElements
*end
=&treholder
->tre
[NUM_TREINHOLDER
-1];
100 struct TrackReallineElements
*tre
=&treholder
->tre
[0];
101 struct TrackReallineElements
*next
=&treholder
->tre
[1];
112 bool nomoretreelementholders
=false;
114 bool AllocateNewTREelementHolder(void){
115 struct TREelementHolder
*treholder
;
117 fprintf(stderr
,"\n\n\nALLOCATING NEW TREELEMENTHOLDER\n\n\n\n");
119 treholder
=tracker_alloc_clean(sizeof(struct TREelementHolder
),GC_malloc_atomic_uncollectable
);
121 RError("Warning. Could not allocate new TREElementHolder.\n");
122 nomoretreelementholders
=true;
126 SetNextsInATreElementHolder(treholder
);
128 nextfreeelement
=&treholder
->tre
[0];
130 fprintf(stderr
,"Success\n");
136 extern struct Root
*root
;
138 bool FreeASpesifiedWBlockTREelement(
139 struct Tracker_Windows
*window
,
140 struct WBlocks
*wblock
142 struct WTracks
*wtrack
;
144 if( ! wblock
->isgfxdatahere
) return false;
146 FreeAllWTempoNodes(wblock
);
148 tfree(wblock
->wtemponodes
);
149 wblock
->wtemponodes
=NULL
;
151 wtrack
=wblock
->wtracks
;
153 FreeAllRTEelements(wblock
,wtrack
);
154 tfree(wtrack
->trackreallines
);
155 wtrack
->trackreallines
=NULL
;
157 FreeAllWFXnodes(wblock
,wtrack
);
158 tfree(wtrack
->wfxnodes
);
159 wtrack
->wfxnodes
=NULL
;
161 wtrack
=NextWTrack(wtrack
);
163 wblock
->isgfxdatahere
=false;
168 bool FreeANotShowedWBlockTREelement(void){
169 struct Tracker_Windows
*window
=root
->song
->tracker_windows
;
170 struct WBlocks
*wblock
;
174 wblock
=window
->wblocks
;
177 if(wblock
!=window
->wblock
){
178 if( FreeASpesifiedWBlockTREelement(window
,wblock
) ) return true;
180 wblock
=NextWBlock(wblock
);
183 window
=NextWindow(window
);
192 struct TrackReallineElements
*TRE_GetTREelementHard(void){
193 struct TrackReallineElements
*temp
=nextfreeelement
;
197 if(FreeANotShowedWBlockTREelement()){
198 temp
=TRE_GetTREelementHard();
200 if(nomoretreelementholders
){
201 temp
=talloc_atomic_uncollectable(sizeof(struct TrackReallineElements
));
203 if( ! AllocateNewTREelementHolder()){
204 temp
=talloc_atomic_uncollectable(sizeof(struct TrackReallineElements
));
206 temp
=TRE_GetTREelementHard();
211 nextfreeelement
=temp
->next
;
214 temp
->next
=NULL
; //This should not be necesarry. There is a bug somewhere else in the program. (probably removed now)