Some "cast to pointer from integer of different size" warnings removed.
[AROS-Contrib.git] / MultiMedia / radium / common / quantitize.c
blobbedf25b98f26abb55ff582212bd2f577e8ddb70d
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. */
28 #include "nsmtracker.h"
29 #include "placement_proc.h"
30 #include "list_proc.h"
31 #include "undo_tracks_proc.h"
32 #include "undo_range_proc.h"
33 #include "wtracks_proc.h"
34 #include "notes_legalize_proc.h"
35 #include "clipboard_range_copy_proc.h"
36 #include "player_proc.h"
38 #include "quantitize_proc.h"
41 extern struct Root *root;
44 /******************************************************************
45 FUNCTION
46 Quantitize 'toquant' spesified by 'quant'. 'Block' is used
47 to know the last zposition in the block, so that 'toquant' isn't
48 placed after that.
50 EXAMPLES
51 toquant=1,2,3 quant=0.5 -> toquant=1,1,2
52 toquant=1,6,7 quant=0.5 -> toquant=2,0,1
53 toquant=5,0,1 quant=2.0 -> toquant=6,0,1
54 ******************************************************************/
56 void Quantitize(
57 struct Blocks *block,
58 Place *toquant,
59 float quant
61 float toquantfloat;
63 int upto;
65 float diff;
66 float out;
68 if(quant==0.0 || quant/2<0.00002) return;
70 toquantfloat=GetfloatFromPlace(toquant);
72 upto=(int)(toquantfloat/quant);
73 upto*=quant;
75 diff=toquantfloat-upto;
76 out=upto;
78 while(diff>=quant/2){
79 out+=quant;
80 diff-=quant;
83 Float2Placement(out,toquant);
85 if( ! PlaceLegal(block,toquant)){
86 PlaceSetLastPos(block,toquant);
91 /****************************************************************
92 NOTE
93 Could work better.
94 ****************************************************************/
95 void Quantitize_Note(
96 struct Blocks *block,
97 struct Notes **notes,
98 struct Notes *note,
99 float quant
101 Place tempstart,tempend;
102 Place end;
104 PlaceSetLastPos(block,&end);
105 PlaceCopy(&tempstart,&note->l.p);
107 if(PlaceEqual(&end,&note->l.p)){
108 return;
111 Quantitize(block,&note->l.p,quant);
113 if(PlaceEqual(&end,&note->l.p)){
114 PlaceCopy(&note->l.p,&tempstart);
117 PlaceCopy(&tempend,&note->end);
119 Quantitize(block,&note->end,quant);
121 if(PlaceLessOrEqual(&note->end,&note->l.p)){
122 PlaceCopy(&note->end,&tempend);
125 if(PlaceLessOrEqual(&note->end,&note->l.p)){
126 PlaceCopy(&note->l.p,&tempstart);
127 PlaceCopy(&note->end,&tempend);
131 while(PlaceLessOrEqual(&note->end,&note->l.p)){
132 note->end.counter+=quant*note->end.dividor;
133 PlaceHandleOverflow(&note->end); //Haven't checked this too good. A small potensial for the program to hang.
137 if( ! PlaceLegal(block,&note->end)){
138 PlaceSetLastPos(block,&note->end);
141 ListAddElement3(notes,&note->l);
144 void Quantitize_range(
145 struct WBlocks *wblock,
146 float quant
148 struct Tracks *track;
149 struct Notes *notes=NULL;
150 struct Notes *note=NULL;
151 struct Notes *temp;
152 struct LocalZooms *realline1,*realline2;
153 int lokke;
154 Place first,last;
156 PlaceSetFirstPos(&first);
157 PlaceSetLastPos(wblock->block,&last);
159 if( ! wblock->isranged) return;
161 track=ListFindElement1(&wblock->block->tracks->l,wblock->rangex1);
163 realline1=wblock->reallines[wblock->rangey1];
164 realline2=wblock->reallines[wblock->rangey2];
166 for(lokke=0;lokke<=wblock->rangex2-wblock->rangex1;lokke++){
167 note=NULL;
168 CopyRange_notes(&note,track->notes,&first,&last);
169 for(;;){
170 if(note==NULL) break;
171 if(PlaceGreaterThan(&note->l.p,&realline2->l.p)) break;
172 temp=NextNote(note);
173 if(PlaceGreaterOrEqual(&note->l.p,&realline1->l.p)){
174 Quantitize_Note(wblock->block,&notes,note,quant);
176 note=temp;
178 track->notes=notes;
179 notes=NULL;
180 track=NextTrack(track);
182 LegalizeNotes(wblock->block,track);
187 void Quantitize_track(
188 struct Blocks *block,
189 struct Tracks *track,
190 float quant
192 struct Notes *note=NULL;
193 struct Notes *notes=NULL;
194 struct Notes *temp;
195 Place first,last;
197 PlaceSetFirstPos(&first);
198 PlaceSetLastPos(block,&last);
200 CopyRange_notes(&note,track->notes,&first,&last);
202 while(note!=NULL){
203 temp=NextNote(note);
204 Quantitize_Note(block,&notes,note,quant);
205 note=temp;
207 track->notes=notes;
209 LegalizeNotes(block,track);
213 void Quantitize_block(
214 struct Blocks *block,
215 float quant
217 struct Tracks *track=block->tracks;
219 while(track!=NULL){
220 Quantitize_track(block,track,quant);
221 track=NextTrack(track);
226 void Quantitize_track_CurrPos(
227 struct Tracker_Windows *window
229 struct WBlocks *wblock=window->wblock;
231 PlayStop();
233 Undo_Track_CurrPos(window);
234 Quantitize_track(wblock->block,wblock->wtrack->track,root->quantitize);
236 UpdateAndClearSomeTrackReallinesAndGfxWTracks(
237 window,
238 wblock,
239 window->curr_track,
240 window->curr_track
243 UpdateAndClearSomeTrackReallinesAndGfxWTracks(
244 window,
245 window->wblock,
247 window->wblock->block->num_tracks-1
252 void Quantitize_block_CurrPos(
253 struct Tracker_Windows *window
256 PlayStop();
258 Undo_Range(
259 window,
260 window->wblock->block,
261 0,window->wblock->block->num_tracks-1,
262 window->wblock->curr_realline
265 Quantitize_block(window->wblock->block,root->quantitize);
267 UpdateAndClearSomeTrackReallinesAndGfxWTracks(
268 window,
269 window->wblock,
271 window->wblock->block->num_tracks-1
275 void Quantitize_range_CurrPos(
276 struct Tracker_Windows *window
278 if(!window->wblock->isranged) return;
280 PlayStop();
282 Undo_Range(window,window->wblock->block,window->wblock->rangex1,window->wblock->rangex2,window->wblock->curr_realline);
284 Quantitize_range(window->wblock,root->quantitize);
286 UpdateAndClearSomeTrackReallinesAndGfxWTracks(
287 window,
288 window->wblock,
289 window->wblock->rangex1,
290 window->wblock->rangex2