Icons for Radium and Shellplayer.
[AROS-Contrib.git] / MultiMedia / radium / common / trackreallineelements.c
blob6543a87cc7d80fa5e8dc0be30ef4d36dbbd48b0c
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"
24 #include <gc.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;
39 int notused;
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;
50 // tre->pointer=NULL;
51 nextfreeelement=tre;
55 void FreeAllRTEelements_fromroot(
56 struct TrackReallineElements **to
58 struct TrackReallineElements *rte=*to;
59 struct TrackReallineElements *temp;
61 if(rte==NULL) return;
63 for(;rte!=NULL;temp=rte,rte=rte->next);
65 temp->next=nextfreeelement;
66 nextfreeelement=*to;
67 *to=NULL;
69 #if 0
70 while(rte!=NULL){
71 temp=rte->next;
72 ReturnRTEelement(rte);
73 rte=temp;
75 *to=NULL;
76 #endif
79 #if 0
80 void FreeAllRTEelements_fromroot(
81 struct TrackReallineElements **to
83 struct TrackReallineElements *rte= *to;
84 struct TrackReallineElements *temp;
86 while(rte!=NULL){
87 temp=rte->next;
88 ReturnRTEelement(rte);
89 rte=temp;
91 *to=NULL;
93 #endif
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];
103 while(next<=end){
104 tre->next=next;
105 tre=next;
106 next=next+1;
109 end->next=NULL;
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);
120 if(treholder==NULL){
121 RError("Warning. Could not allocate new TREElementHolder.\n");
122 nomoretreelementholders=true;
123 return false;
126 SetNextsInATreElementHolder(treholder);
128 nextfreeelement=&treholder->tre[0];
130 fprintf(stderr,"Success\n");
131 return true;
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;
152 while(wtrack!=NULL){
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;
165 return true;
168 bool FreeANotShowedWBlockTREelement(void){
169 struct Tracker_Windows *window=root->song->tracker_windows;
170 struct WBlocks *wblock;
172 while(window!=NULL){
174 wblock=window->wblocks;
176 while(wblock!=NULL){
177 if(wblock!=window->wblock){
178 if( FreeASpesifiedWBlockTREelement(window,wblock) ) return true;
180 wblock=NextWBlock(wblock);
183 window=NextWindow(window);
186 return false;
192 struct TrackReallineElements *TRE_GetTREelementHard(void){
193 struct TrackReallineElements *temp=nextfreeelement;
195 if(temp==NULL){
196 printf("jaaaa\n");
197 if(FreeANotShowedWBlockTREelement()){
198 temp=TRE_GetTREelementHard();
199 }else{
200 if(nomoretreelementholders){
201 temp=talloc_atomic_uncollectable(sizeof(struct TrackReallineElements));
202 }else{
203 if( ! AllocateNewTREelementHolder()){
204 temp=talloc_atomic_uncollectable(sizeof(struct TrackReallineElements));
205 }else{
206 temp=TRE_GetTREelementHard();
210 }else{
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)
215 return temp;