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 /******************************************************************
46 Quantitize 'toquant' spesified by 'quant'. 'Block' is used
47 to know the last zposition in the block, so that 'toquant' isn't
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 ******************************************************************/
68 if(quant
==0.0 || quant
/2<0.00002) return;
70 toquantfloat
=GetfloatFromPlace(toquant
);
72 upto
=(int)(toquantfloat
/quant
);
75 diff
=toquantfloat
-upto
;
83 Float2Placement(out
,toquant
);
85 if( ! PlaceLegal(block
,toquant
)){
86 PlaceSetLastPos(block
,toquant
);
91 /****************************************************************
94 ****************************************************************/
101 Place tempstart
,tempend
;
104 PlaceSetLastPos(block
,&end
);
105 PlaceCopy(&tempstart
,¬e
->l
.p
);
107 if(PlaceEqual(&end
,¬e
->l
.p
)){
111 Quantitize(block
,¬e
->l
.p
,quant
);
113 if(PlaceEqual(&end
,¬e
->l
.p
)){
114 PlaceCopy(¬e
->l
.p
,&tempstart
);
117 PlaceCopy(&tempend
,¬e
->end
);
119 Quantitize(block
,¬e
->end
,quant
);
121 if(PlaceLessOrEqual(¬e
->end
,¬e
->l
.p
)){
122 PlaceCopy(¬e
->end
,&tempend
);
125 if(PlaceLessOrEqual(¬e
->end
,¬e
->l
.p
)){
126 PlaceCopy(¬e
->l
.p
,&tempstart
);
127 PlaceCopy(¬e
->end
,&tempend
);
131 while(PlaceLessOrEqual(¬e->end,¬e->l.p)){
132 note->end.counter+=quant*note->end.dividor;
133 PlaceHandleOverflow(¬e->end); //Haven't checked this too good. A small potensial for the program to hang.
137 if( ! PlaceLegal(block
,¬e
->end
)){
138 PlaceSetLastPos(block
,¬e
->end
);
141 ListAddElement3(notes
,¬e
->l
);
144 void Quantitize_range(
145 struct WBlocks
*wblock
,
148 struct Tracks
*track
;
149 struct Notes
*notes
=NULL
;
150 struct Notes
*note
=NULL
;
152 struct LocalZooms
*realline1
,*realline2
;
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
++){
168 CopyRange_notes(¬e
,track
->notes
,&first
,&last
);
170 if(note
==NULL
) break;
171 if(PlaceGreaterThan(¬e
->l
.p
,&realline2
->l
.p
)) break;
173 if(PlaceGreaterOrEqual(¬e
->l
.p
,&realline1
->l
.p
)){
174 Quantitize_Note(wblock
->block
,¬es
,note
,quant
);
180 track
=NextTrack(track
);
182 LegalizeNotes(wblock
->block
,track
);
187 void Quantitize_track(
188 struct Blocks
*block
,
189 struct Tracks
*track
,
192 struct Notes
*note
=NULL
;
193 struct Notes
*notes
=NULL
;
197 PlaceSetFirstPos(&first
);
198 PlaceSetLastPos(block
,&last
);
200 CopyRange_notes(¬e
,track
->notes
,&first
,&last
);
204 Quantitize_Note(block
,¬es
,note
,quant
);
209 LegalizeNotes(block
,track
);
213 void Quantitize_block(
214 struct Blocks
*block
,
217 struct Tracks
*track
=block
->tracks
;
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
;
233 Undo_Track_CurrPos(window
);
234 Quantitize_track(wblock
->block
,wblock
->wtrack
->track
,root
->quantitize
);
236 UpdateAndClearSomeTrackReallinesAndGfxWTracks(
243 UpdateAndClearSomeTrackReallinesAndGfxWTracks(
247 window->wblock->block->num_tracks-1
252 void Quantitize_block_CurrPos(
253 struct Tracker_Windows
*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(
271 window
->wblock
->block
->num_tracks
-1
275 void Quantitize_range_CurrPos(
276 struct Tracker_Windows
*window
278 if(!window
->wblock
->isranged
) return;
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(
289 window
->wblock
->rangex1
,
290 window
->wblock
->rangex2