~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/waveedit/waveview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Eric Hedekar, Eric Hedekar, Fabrice Coutadeur
  • Date: 2010-01-26 02:32:14 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100126023214-8ez2g5d26d9p584j
Tags: 1.0.1-0ubuntu1
[ Eric Hedekar ]
* New upstream version (LP: #479688)
* Removed patches that were fixed in upstream source
  -[10_64bit_memcorruption_fix]
  -[10_gcc43_build_fixes]
  -[10_lash_private_api_fix]
  -[10_log2f_aliasing_fix]
  -[10_vamgui_init_fix]
  -[20_fix_const]

[ Fabrice Coutadeur ]
* debian/watch: added watch file
* debian/muse.desktop: deleted deprecated Encoding key, Application category
  and icon extension. This fix several warning with lintian and
  desktop-file-validate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//=========================================================
2
2
//  MusE
3
3
//  Linux Music Editor
4
 
//    $Id: waveview.cpp,v 1.10.2.8 2005/12/28 22:17:54 spamatica Exp $
 
4
//    $Id: waveview.cpp,v 1.10.2.16 2009/11/14 03:37:48 terminator356 Exp $
5
5
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
6
6
//=========================================================
7
7
 
24
24
#include "audio.h"
25
25
#include "gconfig.h"
26
26
 
 
27
bool modifyWarnedYet = false;
27
28
//---------------------------------------------------------
28
29
//   WaveView
29
30
//---------------------------------------------------------
86
87
      int h  = hh/2;
87
88
      int y  = rr.y() + h;
88
89
 
 
90
      // Added by T356.
 
91
      int xScale = xmag;
 
92
      if (xScale < 0)
 
93
            xScale = -xScale;
 
94
      
89
95
      for (iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) {
90
96
            WavePart* wp = (WavePart*)(ip->second);
91
97
            int channels = wp->track()->channels();
99
105
                  SndFileR f = event.sndFile();
100
106
                  if (f.isNull())
101
107
                        continue;
102
 
                  int xScale = xmag;
103
 
                  if (xScale < 0)
104
 
                        xScale = -xScale;
105
 
 
 
108
                  
 
109
                  unsigned peoffset = px + event.frame() - event.spos();
106
110
                  int sx, ex;
107
 
                  sx = event.frame() + px + xScale/2 - startSample;
108
 
                  ex = sx + px + event.lenFrame();
 
111
                  
 
112
                  sx = event.frame() + px + xScale/2;
 
113
                  ex = sx + event.lenFrame();
109
114
                  sx = sx / xScale - xpos;
110
115
                  ex = ex / xScale - xpos;
111
116
 
115
120
                        ex = x2;
116
121
 
117
122
                  int pos = (xpos + sx) * xScale + event.spos() - event.frame() - px;
 
123
                  
118
124
                  //printf("pos=%d xpos=%d sx=%d ex=%d xScale=%d event.spos=%d event.frame=%d px=%d\n",
119
125
                  //      pos, xpos, sx, ex, xScale, event.spos(), event.frame(), px);
 
126
                  
120
127
                  h       = hh / (channels * 2);
121
128
                  int cc  = hh % (channels * 2) ? 0 : 1;
122
129
 
128
135
                        if (pos < event.spos())
129
136
                              continue;
130
137
 
131
 
                        unsigned peoffset = px + event.frame() - event.spos();
132
138
                        int selectionStartPos = selectionStart - peoffset; // Offset transformed to event coords
133
139
                        int selectionStopPos  = selectionStop  - peoffset;
134
140
 
135
 
 
136
 
 
137
141
                        for (int k = 0; k < channels; ++k) {
138
142
                              int kk = k % f.channels();
139
143
                              int peak = (sa[kk].peak * (h - 1)) / yScale;
144
148
                                    rms = h;
145
149
                              QColor peak_color = QColor(darkGray);
146
150
                              QColor rms_color  = QColor(black);
147
 
                              if (pos > selectionStartPos && pos < selectionStopPos) {
 
151
                              
 
152
                              // Changed by T356. Reduces (but not eliminates) drawing artifacts.
 
153
                              //if (pos > selectionStartPos && pos < selectionStopPos) {
 
154
                              if (pos > selectionStartPos && pos <= selectionStopPos) {
 
155
                                    
148
156
                                    peak_color = QColor(lightGray);
149
157
                                    rms_color  = QColor(white);
150
158
                                    // Draw inverted
191
199
      if (pos[2] >= x && pos[2] < x2)
192
200
            p.drawLine(pos[2], y, pos[2], y2);
193
201
 
194
 
      int n  = curPart->track()->channels();
 
202
      // Changed by T356. Support multiple (or none) selected parts.
 
203
      //int n  = curPart->track()->channels();
 
204
      int n = 1;
 
205
      if(curPart)
 
206
        n = curPart->track()->channels();
 
207
      
195
208
      int hn = h / n;
196
209
      int hh = hn / 2;
197
210
      for (int i = 0; i < n; ++i) {
210
223
 
211
224
QString WaveView::getCaption() const
212
225
      {
213
 
      return QString("Part ") + curPart->name();
 
226
      
 
227
      // Changed by T356. Support multiple (or none) selected parts.
 
228
      //return QString("Part ") + curPart->name();
 
229
      if(curPart)
 
230
        return QString("Part ") + curPart->name();
 
231
      else  
 
232
        return QString("Part ");
 
233
        
214
234
      }
215
235
 
216
236
//---------------------------------------------------------
219
239
 
220
240
void WaveView::songChanged(int flags)
221
241
      {
 
242
      // Is it simply a midi controller value adjustment? Forget it.
 
243
      if(flags == SC_MIDI_CONTROLLER)
 
244
        return;
 
245
    
222
246
      if (flags & SC_SELECTION) {
223
247
            startSample  = MAXINT;
224
248
            endSample    = 0;
271
295
                        break;
272
296
                  case Song::JUMP:
273
297
                        if (npos >= width()) {
274
 
                              int ppos =  val - rmapxDev(width()/4);
 
298
                              int ppos =  val - xorg - rmapxDev(width()/4);
275
299
                              if (ppos < 0)
276
300
                                    ppos = 0;
277
301
                              emit followEvent(ppos);
279
303
                              npos = mapx(val);
280
304
                              }
281
305
                        else if (npos < 0) {
282
 
                              int ppos =  val - rmapxDev(width()*3/4);
 
306
                              int ppos =  val - xorg - rmapxDev(width()*3/4);
283
307
                              if (ppos < 0)
284
308
                                    ppos = 0;
285
309
                              emit followEvent(ppos);
289
313
                        break;
290
314
                  case Song::CONTINUOUS:
291
315
                        if (npos > (width()*5)/8) {
292
 
                              int ppos =  pos[idx] - rmapxDev(width()*5/8);
 
316
                              int ppos =  pos[idx] - xorg - rmapxDev(width()*5/8);
293
317
                              if (ppos < 0)
294
318
                                    ppos = 0;
295
319
                              emit followEvent(ppos);
297
321
                              npos = mapx(val);
298
322
                              }
299
323
                        else if (npos < (width()*3)/8) {
300
 
                              int ppos =  pos[idx] - rmapxDev(width()*3/8);
 
324
                              int ppos =  pos[idx] - xorg - rmapxDev(width()*3/8);
301
325
                              if (ppos < 0)
302
326
                                    ppos = 0;
303
327
                              emit followEvent(ppos);
410
434
 
411
435
void WaveView::range(int* s, int *e)
412
436
      {
413
 
      *s = curPart->frame();
414
 
      int etick = curPart->tick() + curPart->lenTick();
415
 
      *e = tempomap.tick2frame(etick);
416
 
      }
417
 
 
 
437
      
 
438
      PartList* lst = editor->parts();
 
439
      if(lst->empty())
 
440
      {
 
441
        *s = 0;
 
442
        *e = tempomap.tick2frame(song->len());
 
443
        return;  
 
444
      }
 
445
      int ps = song->len(), pe = 0;
 
446
      int tps, tpe;
 
447
      for(iPart ip = lst->begin(); ip != lst->end(); ++ip) 
 
448
      {
 
449
        tps = ip->second->tick();
 
450
        if(tps < ps)
 
451
          ps = tps;
 
452
        tpe = tps + ip->second->lenTick();
 
453
        if(tpe > pe)
 
454
          pe = tpe;
 
455
      }
 
456
      *s = tempomap.tick2frame(ps);
 
457
      *e = tempomap.tick2frame(pe);
 
458
      }
418
459
 
419
460
//---------------------------------------------------------
420
461
//   cmd
512
553
                  printf("No selection. Ignoring\n"); //@!TODO: Disable menu options when no selection
513
554
                  return;
514
555
                  }
 
556
            
 
557
            //if(!modifyWarnedYet)
 
558
            //{
 
559
            //  modifyWarnedYet = true;
 
560
            //  if(QMessageBox::warning(this, QString("Muse"),
 
561
            //     tr("Warning! Muse currently operates directly on the sound file.\n"
 
562
            //        "Undo is supported, but NOT after exit, WITH OR WITHOUT A SAVE!\n"
 
563
            //        "If you are stuck, try deleting the associated .wca file and reloading."), tr("&Ok"), tr("&Cancel"),
 
564
            //     QString::null, 0, 1 ) != 0)
 
565
            //   return;
 
566
            //}
515
567
            modifySelection(modifyoperation, selectionStart, selectionStop, paramA);
516
568
            }
517
569
      }
527
579
      for (iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) {
528
580
            WavePart* wp = (WavePart*)(ip->second);
529
581
            unsigned part_offset = wp->frame();
 
582
            
530
583
            EventList* el = wp->events();
 
584
            //printf("eventlist length=%d\n",el->size());
531
585
 
532
586
            for (iEvent e = el->begin(); e != el->end(); ++e) {
533
587
                  Event event  = e->second;
536
590
                  SndFileR file = event.sndFile();
537
591
                  if (file.isNull())
538
592
                        continue;
539
 
 
 
593
                  
540
594
                  unsigned event_offset = event.frame() + part_offset;
541
595
                  unsigned event_startpos  = event.spos();
542
596
                  unsigned event_length = event.lenFrame() + event.spos();
543
597
                  unsigned event_end    = event_offset + event_length;
544
598
                  //printf("startpos=%d stoppos=%d part_offset=%d event_offset=%d event_startpos=%d event_length=%d event_end=%d\n", startpos, stoppos, part_offset, event_offset, event_startpos, event_length, event_end);
545
599
 
546
 
                  if (!(event_end <= startpos || event_offset >= stoppos)) {
 
600
                  if (!(event_end <= startpos || event_offset > stoppos)) {
547
601
                        int tmp_sx = startpos - event_offset + event_startpos;
548
602
                        int tmp_ex = stoppos  - event_offset + event_startpos;
549
603
                        unsigned sx;
556
610
                        WaveEventSelection s;
557
611
                        s.file = file;
558
612
                        s.startframe = sx;
559
 
                        s.endframe   = ex;
 
613
                        s.endframe   = ex+1;
 
614
                        //printf("sx=%d ex=%d\n",sx,ex);
560
615
                        selection.push_back(s);
561
616
                        }
562
617
                  }
732
787
//---------------------------------------------------------
733
788
void WaveView::reverseSelection(unsigned channels, float** data, unsigned length)
734
789
      {
 
790
      if(length <= 1)    
 
791
        return;
735
792
      for (unsigned i=0; i<channels; i++) {
736
793
            for (unsigned j=0; j<length/2; j++) {
737
794
                  float tmpl = data[i][j];
738
 
                  float tmpr = data[i][length - j];
 
795
                  float tmpr = data[i][length - j - 1];
739
796
                  data[i][j] = tmpr;
740
 
                  data[i][length - j] = tmpl;
 
797
                  data[i][length - j - 1] = tmpl;
741
798
                  }
742
799
            }
743
800
      }
744
 
 
745
801
//---------------------------------------------------------
746
802
//   applyGain
747
803
//---------------------------------------------------------
779
835
      // Forkaborkabork
780
836
      int pid = fork();
781
837
      if (pid == 0) {
782
 
            if (execlp(config.externalWavEditor.latin1(), config.externalWavEditor.latin1(), exttmpFileName.latin1(), 0) == -1) {
 
838
            if (execlp(config.externalWavEditor.latin1(), config.externalWavEditor.latin1(), exttmpFileName.latin1(), NULL) == -1) {
783
839
                  perror("Failed to launch external editor");
784
840
                  // Get out of here
785
841