Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[429088]: kwave / sampleedit.cpp Maximize Restore History

Download this file

sampleedit.cpp    352 lines (320 with data), 8.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#include <unistd.h>
#include "sample.h"
#include <kmsgbox.h>
#include <kprogress.h>
#include <limits.h>
#include "clipboard.h"
extern ClipBoard *clipboard;
//**********************************************************
void MSignal::toggleChannel (int a,int b)
{
if (a<b)
{
if (next) next->toggleChannel (a+1,b);
}
else
{
selected=!selected;
}
}
//**********************************************************
void MSignal::deleteChannel (int a,int b)
{
if (a<b)
{
if (next)
{
if (a==b-1)
{
MSignal *todump=next;
next=next->getNext();
todump->detachChannels();
delete todump;
}
else
deleteChannel (a+1,b);
}
}
}
//**********************************************************
void MSignal::addChannel ()
{
MSignal *ins=new MSignal (parent,length,rate,1);
this->appendChannel (ins);
emit sampleChanged();
}
//**********************************************************
void MSignal::setChannels (int num)
{
channels=num;
}
//**********************************************************
void MSignal::appendChannel (MSignal *ins)
{
MSignal *tmp=this;
while (tmp->getNext()!=0) tmp=tmp->getNext(); //find last channel
tmp->appendChanneltoThis (ins);
channels++;
}
//**********************************************************
void MSignal::appendChanneltoThis (MSignal *ins)
{
next=ins;
}
//**********************************************************
void MSignal::copyRange ()
{
if (clipboard) //kill current clipboard if it exists...
{
delete clipboard;
clipboard=0;
}
MSignal *tmp=this;
while (tmp!=0)
{
if (tmp->isSelected()) tmp->copyChannelRange ();
tmp=tmp->getNext();
}
}
//**********************************************************
void MSignal::copyChannelRange ()
{
MSignal *temp;
int *tsample;
if (rmarker!=lmarker) //this function makes no sense if there is no Range is selected
{
if (lmarker<0) lmarker=0;
if (rmarker>length) rmarker=length;
temp=new MSignal (parent,manage,rmarker-lmarker,rate);
if (temp)
{
int j=0;
tsample=temp->getSample();
for (int i=lmarker;i<rmarker;tsample[j++]=sample[i++]);
if (!clipboard) clipboard=new ClipBoard (temp);
else clipboard->appendChannel(temp);
emit sampleChanged();
}
else KMsgBox::message (parent,"Info","Not enough Memory for Operation !",2);
}
}
//**********************************************************
void MSignal::pasteRange ()
{
if (clipboard)
{
MSignal *clip=clipboard->getSignal();
MSignal *tmp=this;
int all=true;
while (tmp!=0) //check if all Channels are selected ....
{
if (!tmp->isSelected()) all=false;
tmp=tmp->getNext();
}
tmp=this;
if (all)
{
while (tmp!=0)
{
tmp->pasteChannelRange (clip);
clip=clip->getNext();
if (!clip) clip=clipboard->getSignal();
tmp=tmp->getNext();
}
}
else
{
while (tmp!=0)
{
if (tmp->isSelected())
tmp->overwriteChannelRange (clip);
clip=clip->getNext();
if (!clip) clip=clipboard->getSignal();
tmp=tmp->getNext();
}
}
emit sampleChanged();
}
}
//**********************************************************
void MSignal::overwriteChannelRange (MSignal *clipboard)
{
if (lmarker<0) lmarker=0;
if (rmarker>length) rmarker=length;
int *clipsam =clipboard->getSample();
int cliplength =clipboard->getLength();
if (cliplength>length-lmarker) cliplength=length-lmarker;
memcpy (&sample[lmarker],clipsam,(cliplength)*sizeof(int));
rmarker=lmarker+cliplength;
}
//**********************************************************
void MSignal::pasteChannelRange (MSignal *clipboard)
{
int *newsam;
if (lmarker<0) lmarker=0;
if (rmarker>length) rmarker=length;
int *clipsam =clipboard->getSample();
int cliplength =clipboard->getLength();
newsam=getNewMem(length+cliplength-(rmarker-lmarker));
if (newsam)
{
int r=rmarker;
int l=lmarker;
memcpy (newsam,sample,lmarker*sizeof(int));
memcpy (&newsam[lmarker],clipsam,(cliplength)*sizeof(int));
memcpy (&newsam[lmarker+cliplength],&sample[rmarker],(length-rmarker)*sizeof(int));
getridof (sample);
sample=newsam;
length+=cliplength-(rmarker-lmarker);
rmarker=lmarker+cliplength;
if (cliplength-(r-l)>0)
emit signalinserted (l,cliplength-(r-l));
else
emit signaldeleted (l,-(cliplength-(r-l)));
}
else KMsgBox::message (parent,"Info","Not enough Memory for Operation !",2);
}
//**********************************************************
void MSignal::mixpasteRange ()
{
if (clipboard)
{
int *newsam;
int len;
if (lmarker<0) lmarker=0;
if (rmarker>length) rmarker=length;
len=rmarker-lmarker;
int *clipsam =(clipboard->getSignal())->getSample();
int cliplength =clipboard->getLength();
if (len>0)
{
for (int i=0;(i<len)&&(i<cliplength);i++) // mix range with clipboard...
sample[lmarker+i]=(sample[lmarker+i]+clipsam[i])/2;
emit sampleChanged();
}
else
{
if (lmarker<length-cliplength)
{
for (int i=0;i<cliplength;i++) // mix clipboard to signal
sample[lmarker+i]=(sample[lmarker+i]+clipsam[i])/2;
emit sampleChanged();
}
else
{ //not so simple, need to append ...
newsam=getNewMem(cliplength+lmarker);
if (newsam)
{
memcpy (newsam,sample,lmarker*sizeof(int));
for (int i=lmarker;i<length;i++)
newsam[i]=(sample[i]+clipsam[i-lmarker])/2;
for (int i=length;i<cliplength+lmarker;i++)
newsam[i]=clipsam[i-lmarker]/2;
getridof (sample);
sample=newsam;
length=cliplength+lmarker;
rmarker=lmarker+cliplength;
emit sampleChanged();
}
else KMsgBox::message (parent,"Info","Not enough Memory for Operation !",2);
}
}
}
}
//**********************************************************
void MSignal::cutRange ()
{
copyRange();
deleteRange();
}
//**********************************************************
void MSignal::deleteRange ()
{
MSignal *tmp=this;
int all=true;
while (tmp!=0)
{
if (!tmp->isSelected()) all=false;
tmp=tmp->getNext();
}
tmp=this;
if (all)
{
while (tmp!=0)
{
tmp->deleteChannelRange();
tmp=tmp->getNext();
}
}
else
{
while (tmp!=0)
{
if (tmp->isSelected()) tmp->zeroChannelRange();
tmp=tmp->getNext();
}
}
emit sampleChanged();
}
//**********************************************************
void MSignal::deleteChannelRange ()
{
if (rmarker!=lmarker)
{
int *newsam;
if (lmarker<0) lmarker=0;
if (rmarker>length) rmarker=length;
newsam=getNewMem (length-(rmarker-lmarker));
if (newsam)
{
int r=rmarker;
int l=lmarker;
memcpy (newsam,sample,lmarker*sizeof(int));
memcpy (&newsam[lmarker],&sample[rmarker],(length-rmarker)*sizeof(int));
getridof (sample);
sample=newsam;
length=length-(rmarker-lmarker);
rmarker=lmarker;
emit signaldeleted (l,r-l);
}
else KMsgBox::message (parent,"Info","Not enough Memory for Operation !",2);
}
}
//**********************************************************
void MSignal::cropRange ()
{
MSignal *tmp=this;
while (tmp!=0)
{
tmp->cropChannelRange ();
tmp=tmp->getNext();
}
emit sampleChanged();
}
//**********************************************************
void MSignal::cropChannelRange ()
{
if (rmarker!=lmarker)
{
int *newsam;
if (lmarker<0) lmarker=0;
if (rmarker>length) rmarker=length;
newsam=getNewMem(rmarker-lmarker);
if (newsam)
{
int r=rmarker;
int l=lmarker;
int le=length;
memcpy (newsam,&sample[lmarker],(rmarker-lmarker)*sizeof(int));
getridof (sample);
sample=newsam;
length=rmarker-lmarker;
rmarker=0;
lmarker=0;
emit signaldeleted (0,r);
emit signaldeleted (l,le-r);
}
else KMsgBox::message (parent,"Info","Not enough Memory for Operation !",2);
}
}
//**********************************************************