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

« back to all changes in this revision

Viewing changes to muse/track.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-07-18 16:07:06 UTC
  • mfrom: (1.1.12) (10.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120718160706-qy1lydijykeiqqmg
Tags: 2.0-1
* New stable release.
* debian/rules: Exclude muse/widgets/arrangercolumns.{cpp,h}~ from being
  deleted by dh_clean.
* Drop 0002-gcc_hardening.patch, applied upstream.
* Drop 0003-ftbfs_gcc47.patch, applied upstream.
* Refresh 1001-buildsystem.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "audio.h"
34
34
#include "globaldefs.h"
35
35
#include "route.h"
 
36
#include "limits.h"
 
37
#include "dssihost.h"
36
38
 
37
39
namespace MusECore {
38
40
 
39
 
//bool Track::_isVisible=true;
40
41
unsigned int Track::_soloRefCnt  = 0;
41
42
Track* Track::_tmpSoloChainTrack = 0;
42
43
bool Track::_tmpSoloChainDoIns   = false;
43
44
bool Track::_tmpSoloChainNoDec   = false;
44
 
//bool Track::_tmpIsAuxProcessing  = false; 
45
 
//int Track::_tmpIsAuxProcRefCount = 0; 
46
45
 
47
46
const char* Track::_cname[] = {
48
47
      "Midi", "Drum", "Wave", "AudioOut", "AudioIn", "AudioGroup", 
110
109
  {
111
110
    Part* part = ip->second;
112
111
    const EventList* el = part->cevents();
113
 
    //unsigned len = part->lenTick();
114
112
    for(ciEvent ie = el->begin(); ie != el->end(); ++ie)
115
113
    {
116
114
      const Event& ev = ie->second;
117
 
      // Added by T356. Do not remove events which are past the end of the part.
118
 
      // No, actually, do remove ALL of them belonging to the part.
119
 
      // Just in case there are stray values left after the part end.
120
 
      //if(ev.tick() >= len)
121
 
      //  break;
122
115
                    
123
116
      if(ev.type() == Controller)
124
117
      {
156
149
  {
157
150
    case Track::AUDIO_AUX:
158
151
        return AudioAux::visible();
159
 
        break;
160
152
    case Track::AUDIO_GROUP:
161
153
        return AudioGroup::visible();
162
154
    case Track::AUDIO_INPUT:
166
158
    case Track::WAVE:
167
159
        return WaveTrack::visible();
168
160
    case Track::MIDI:
 
161
    case Track::DRUM:
169
162
        return MidiTrack::visible();
170
163
    case Track::AUDIO_SOFTSYNTH:
171
 
        return AudioAux::visible();
 
164
        return SynthI::visible();
172
165
  default:
173
166
    break;
174
167
  }
222
215
      _height        = 20;
223
216
      _locked        = false;
224
217
      for (int i = 0; i < MAX_CHANNELS; ++i) {
225
 
            //_meter[i] = 0;
226
 
            //_peak[i]  = 0;
227
218
            _meter[i] = 0.0;
228
219
            _peak[i]  = 0.0;
229
220
            }
239
230
{
240
231
      internal_assign(t, flags | ASSIGN_PROPERTIES);  
241
232
      for (int i = 0; i < MAX_CHANNELS; ++i) {
242
 
            //_meter[i] = 0;
243
 
            //_peak[i]  = 0;
244
233
            _meter[i] = 0.0;
245
234
            _peak[i]  = 0.0;
246
235
            }
287
276
        _type         = t.type();
288
277
        _locked       = t.locked();
289
278
 
290
 
        //_name         = t.name();
291
279
        _name =  t.name() + " #";
292
280
        for(int i = 2; true; ++i) 
293
281
        {
300
288
            // Do not call setName here. Audio Input and Output override it and try to set 
301
289
            //  Jack ports, which have not been initialized yet here. Must wait until 
302
290
            // .Audio Input and Output copy constructors or assign are called.
303
 
            //setName(s);
304
291
            _name = s;
305
292
            break;
306
293
          }
394
381
        continue;
395
382
      p->enableAllControllers(true);
396
383
    }
397
 
      
 
384
 
 
385
    if(type() == AUDIO_SOFTSYNTH)
 
386
    {
 
387
      SynthI* synth = static_cast<SynthI*>(this);
 
388
      if(synth->synth() && synth->synth()->synthType() == Synth::DSSI_SYNTH)
 
389
      {
 
390
        SynthIF* sif = synth->sif();
 
391
        if(sif)
 
392
        {
 
393
          DssiSynthIF* dssi_sif = static_cast<DssiSynthIF*>(sif);
 
394
          dssi_sif->enableAllControllers(true);
 
395
        }
 
396
      }
 
397
    }
 
398
    
398
399
    if(clearList)
399
400
      t->recEvents()->clear();
400
401
}
417
418
 
418
419
void Track::updateAuxRoute(int refInc, Track* dst)
419
420
{
420
 
  //if(isMidiTrack() || _type == AUDIO_AUX)
421
421
  if(isMidiTrack())
422
422
    return;
423
423
  
424
 
  //printf("Track::updateAuxRoute %s _auxRouteCount:%d refInc:%d\n", name().toLatin1().constData(), _auxRouteCount, refInc); 
425
 
 
426
424
  if(dst)
427
425
  {  
428
426
    _nodeTraversed = true;
450
448
  if(_auxRouteCount < 0)
451
449
  {
452
450
    fprintf(stderr, "Track::updateAuxRoute Ref underflow! %s _auxRouteCount:%d refInc:%d\n", name().toLatin1().constData(), _auxRouteCount, refInc); 
453
 
    //_auxRouteCount = 0;    
454
451
  }
455
452
  
456
453
  for (iRoute i = _outRoutes.begin(); i != _outRoutes.end(); ++i) 
458
455
    if( !(*i).isValid() || (*i).type != Route::TRACK_ROUTE )
459
456
      continue;
460
457
    Track* t = (*i).track;
461
 
    //if(t->isMidiTrack())
462
 
    //  continue;
463
458
    t->updateAuxRoute(refInc, NULL);
464
459
  }
465
460
  
474
469
 
475
470
bool Track::isCircularRoute(Track* dst)
476
471
{
477
 
  //if(isMidiTrack() || _type == AUDIO_AUX)
478
 
  //if(isMidiTrack())
479
 
  //  return;
480
 
  
481
472
  bool rv = false;
482
473
  
483
474
  if(dst)
485
476
    _nodeTraversed = true;
486
477
    rv = dst->isCircularRoute(NULL);
487
478
    _nodeTraversed = false;
488
 
    //if(rv)
489
 
    //  fprintf(stderr, "  Circular route %s -> %s\n", name().toLatin1().constData(), dst->name().toLatin1().constData()); 
490
479
    return rv;
491
480
  }
492
481
  
500
489
    if( !(*i).isValid() || (*i).type != Route::TRACK_ROUTE )
501
490
      continue;
502
491
    Track* t = (*i).track;
503
 
    //if(t->isMidiTrack())
504
 
    //  continue;
505
492
    rv = t->isCircularRoute(NULL);
506
493
    if(rv)
507
494
      break; 
552
539
        clefType       = mt.clefType;
553
540
      }  
554
541
      
555
 
      // FIXME: May get "addRoute: src track route already exists" when say, 
556
 
      //         an audio output and wave track are selected just because
557
 
      //         of the redundancy (wave track wants to connect to output by default).
558
542
      if(flags & ASSIGN_ROUTES)
559
543
      {
560
544
        for(ciRoute ir = mt._inRoutes.begin(); ir != mt._inRoutes.end(); ++ir)
561
 
          // Amazingly, this single line seems to work.
562
 
          MusEGlobal::audio->msgAddRoute(*ir, Route(this, ir->channel));
 
545
          // Don't call msgAddRoute. Caller later calls msgAddTrack which 'mirrors' this routing node.
 
546
          _inRoutes.push_back(*ir); 
563
547
        
564
548
        for(ciRoute ir = mt._outRoutes.begin(); ir != mt._outRoutes.end(); ++ir)
565
 
          // Amazingly, this single line seems to work.
566
 
          MusEGlobal::audio->msgAddRoute(Route(this, ir->channel), *ir);
 
549
          // Don't call msgAddRoute. Caller later calls msgAddTrack which 'mirrors' this routing node.
 
550
         _outRoutes.push_back(*ir); 
567
551
      }
568
552
      else if(flags & ASSIGN_DEFAULT_ROUTES)
569
553
      {
578
562
          {
579
563
            c = mp->defaultInChannels();
580
564
            if(c)
581
 
            {
582
 
              MusEGlobal::audio->msgAddRoute(Route(i, c), Route(this, c));
583
 
              //updateFlags |= SC_ROUTE;
584
 
            }
 
565
              // Don't call msgAddRoute. Caller later calls msgAddTrack which 'mirrors' this routing node.
 
566
              _inRoutes.push_back(Route(i, c)); 
585
567
          }  
586
568
          
587
 
          if(!defOutFound)                       ///
 
569
          if(!defOutFound)
588
570
          {
589
571
            c = mp->defaultOutChannels();
590
572
            if(c)
592
574
              
593
575
        /// TODO: Switch if and when multiple output routes supported.
594
576
        #if 0
595
 
              MusEGlobal::audio->msgAddRoute(Route(this, c), Route(i, c));
596
 
              //updateFlags |= SC_ROUTE;
 
577
              // Don't call msgAddRoute. Caller later calls msgAddTrack which 'mirrors' this routing node.
 
578
              _outRoutes.push_back(Route(i, c)); 
597
579
        #else 
598
580
              for(ch = 0; ch < MIDI_CHANNELS; ++ch)   
599
581
              {
604
586
                  _outPort = i;
605
587
                  if(type() != Track::DRUM)  // Leave drum tracks at channel 10.
606
588
                    _outChannel = ch;
607
 
                  //updateFlags |= SC_ROUTE;
608
589
                  break;               
609
590
                }
610
591
              }
636
617
      {
637
618
      _outPort       = 0;
638
619
      _outChannel    = 0;
639
 
      //_inPortMask    = 0xffff;
640
 
      ///_inPortMask    = 0xffffffff;
641
 
      
642
 
      ///_inChannelMask = 0xffff;      // "ALL"
 
620
 
643
621
      transposition  = 0;
644
622
      velocity       = 0;
645
623
      delay          = 0;
667
645
  if(_outChannel == i)
668
646
    return;
669
647
    
670
 
  //removePortCtrlEvents();
671
648
  removePortCtrlEvents(this);
672
649
  _outChannel = i; 
673
 
  //addPortCtrlEvents();
674
650
  addPortCtrlEvents(this);
675
651
}
676
652
 
683
659
  if(_outPort == i)
684
660
    return;
685
661
  
686
 
  //removePortCtrlEvents();
687
662
  removePortCtrlEvents(this);
688
663
  _outPort = i; 
689
 
  //addPortCtrlEvents();
690
664
  addPortCtrlEvents(this);
691
665
}
692
666
 
699
673
  if(_outPort == port && _outChannel == ch)
700
674
    return;
701
675
  
702
 
  //removePortCtrlEvents();
703
676
  removePortCtrlEvents(this);
704
677
  _outPort = port; 
705
678
  _outChannel = ch;
706
 
  //addPortCtrlEvents();
707
679
  addPortCtrlEvents(this);
708
680
}
709
681
 
715
687
 
716
688
void MidiTrack::setInPortAndChannelMask(unsigned int portmask, int chanmask) 
717
689
718
 
  //if(!portmask || !chanmask)
719
 
  //  return;
720
 
     
721
 
  //RouteList* rl = inRoutes();
722
690
  bool changed = false;
723
691
  
724
692
  for(int port = 0; port < 32; ++port)  // 32 is the old maximum number of ports.
728
696
    if(!MusEGlobal::midiPorts[port].foundInSongFile())
729
697
      continue;
730
698
      
731
 
    //if(!(portmask & (1 << port)))
 
699
    //if(!(portmask & (1 << port))) DELETETHIS 8
732
700
    //  continue;
733
701
    
734
702
    // Removed. Allow to connect to port with no device so user can change device later.
741
709
      Route bRoute(this, chanmask);
742
710
    
743
711
      // Route wanted?
744
 
      //if((portmask & (1 << port)) && (chanmask & (1 << ch)))
745
712
      if(portmask & (1 << port))                                          
746
713
      {
747
 
        // Route already exists?
748
 
        //if(iir != rl->end()) 
749
 
        //  continue;
750
714
        MusEGlobal::audio->msgAddRoute(aRoute, bRoute);
751
715
        changed = true;
752
716
      }
753
717
      else
754
718
      {
755
 
        // Route does not exist?
756
 
        //if(iir == rl->end()) 
757
 
        //  continue;
758
719
        MusEGlobal::audio->msgRemoveRoute(aRoute, bRoute);
759
720
        changed = true;
760
721
      }
761
 
    //}
 
722
    //} DELETETHIS
762
723
  }
763
724
   
764
725
  if(changed)
768
729
  }  
769
730
}
770
731
 
771
 
/*
 
732
/* DELETETHIS 84
772
733
//---------------------------------------------------------
773
734
//   addPortCtrlEvents
774
735
//---------------------------------------------------------
912
873
 
913
874
      xml.intTag(level, "device", outPort());
914
875
      xml.intTag(level, "channel", outChannel());
915
 
      //xml.intTag(level, "inportMap", inPortMask());
916
 
      ///xml.uintTag(level, "inportMap", inPortMask());       // Obsolete
917
 
      ///xml.intTag(level, "inchannelMap", inChannelMask());  // Obsolete
918
876
      xml.intTag(level, "locked", _locked);
919
877
      xml.intTag(level, "echo", _recEcho);
920
878
 
972
930
                        else if (tag == "channel")
973
931
                              setOutChannel(xml.parseInt());
974
932
                        else if (tag == "inportMap")
975
 
                              //setInPortMask(xml.parseInt());
976
 
                              ///setInPortMask(xml.parseUInt());
977
 
                              //xml.skip(tag);                      // Obsolete. 
978
 
                              portmask = xml.parseUInt();           // Support old files.
 
933
                              portmask = xml.parseUInt();           // Obsolete but support old files.
979
934
                        else if (tag == "inchannelMap")
980
 
                              ///setInChannelMask(xml.parseInt());
981
 
                              //xml.skip(tag);                      // Obsolete.
982
 
                              chanmask = xml.parseInt();            // Support old files.
 
935
                              chanmask = xml.parseInt();            // Obsolete but support old files.
983
936
                        else if (tag == "locked")
984
937
                              _locked = xml.parseInt();
985
938
                        else if (tag == "echo")
1176
1129
          
1177
1130
          s = "dest";
1178
1131
          
1179
 
          //if(r->type == Route::MIDI_DEVICE_ROUTE)                                      // Obsolete since 1.1-RC2    
1180
 
          //  s += QString(QT_TRANSLATE_NOOP("@default", " devtype=\"%1\"")).arg(r->device->deviceType());  //
1181
 
          //if(r->type != Route::TRACK_ROUTE)                                            //
1182
1132
          if(r->type != Route::TRACK_ROUTE && r->type != Route::MIDI_PORT_ROUTE)
1183
1133
            s += QString(" type=\"%1\"").arg(r->type);
1184
1134
 
1185
 
          //s += QString(QT_TRANSLATE_NOOP("@default", " name=\"%1\"/")).arg(r->name());
1186
1135
          if(r->type == Route::MIDI_PORT_ROUTE)                                          
1187
1136
            s += QString(" mport=\"%1\"/").arg(r->midiPort);
1188
1137
          else  
1195
1144
      }
1196
1145
}
1197
1146
 
 
1147
int MidiTrack::getFirstControllerValue(int ctrl, int def)
 
1148
{
 
1149
  int val=def;
 
1150
  unsigned tick=-1; // maximum integer
 
1151
  
 
1152
  for (iPart pit=parts()->begin(); pit!=parts()->end(); pit++)
 
1153
  {
 
1154
    Part* part=pit->second;
 
1155
    if (part->tick() > tick) break; // ignore this and the rest. we won't find anything new.
 
1156
    for (iEvent eit=part->events()->begin(); eit!=part->events()->end(); eit++)
 
1157
    {
 
1158
      if (eit->first+part->tick() >= tick) break;
 
1159
      if (eit->first > part->lenTick()) break; // ignore events past the end of the part
 
1160
      // else if (eit->first+part->tick() < tick) and
 
1161
      if (eit->second.type()==Controller && eit->second.dataA()==ctrl)
 
1162
      {
 
1163
        val = eit->second.dataB();
 
1164
        tick = eit->first+part->tick();
 
1165
        break;
 
1166
      }
 
1167
    }
 
1168
  }
 
1169
 
 
1170
  return val;
 
1171
}
 
1172
 
 
1173
int MidiTrack::getControllerChangeAtTick(unsigned tick, int ctrl, int def)
 
1174
{
 
1175
  for (iPart pit=parts()->begin(); pit!=parts()->end(); pit++)
 
1176
  {
 
1177
    Part* part=pit->second;
 
1178
    if (part->tick() > tick) break; // ignore this and the rest. we'd find nothing any more
 
1179
    if (part->endTick() < tick) continue; // ignore only this.
 
1180
    for (iEvent eit=part->events()->begin(); eit!=part->events()->end(); eit++)
 
1181
    {
 
1182
      if (eit->first+part->tick() > tick) break; // we won't find anything in this part from now on.
 
1183
      if (eit->first > part->lenTick()) break; // ignore events past the end of the part
 
1184
      if (eit->first+part->tick() < tick) continue; // ignore only this
 
1185
      
 
1186
      // else if (eit->first+part->tick() == tick) and
 
1187
      if (eit->second.type()==Controller && eit->second.dataA()==ctrl)
 
1188
        return eit->second.dataB();
 
1189
    }
 
1190
  }
 
1191
 
 
1192
  return def;
 
1193
}
 
1194
 
 
1195
// returns the tick where this CC gets overriden by a new one
 
1196
// returns UINT_MAX for "never"
 
1197
unsigned MidiTrack::getControllerValueLifetime(unsigned tick, int ctrl) 
 
1198
{
 
1199
  unsigned result=UINT_MAX;
 
1200
  
 
1201
  for (iPart pit=parts()->begin(); pit!=parts()->end(); pit++)
 
1202
  {
 
1203
    Part* part=pit->second;
 
1204
    if (part->tick() > result) break; // ignore this and the rest. we won't find anything new.
 
1205
    if (part->endTick() < tick) continue; // ignore only this part, we won't find anything there.
 
1206
    for (iEvent eit=part->events()->begin(); eit!=part->events()->end(); eit++)
 
1207
    {
 
1208
      if (eit->first+part->tick() >= result) break;
 
1209
      if (eit->first > part->lenTick()) break; // ignore events past the end of the part
 
1210
      // else if (eit->first+part->tick() < result) and
 
1211
      if (eit->first+part->tick() > tick &&
 
1212
          eit->second.type()==Controller && eit->second.dataA()==ctrl)
 
1213
      {
 
1214
        result = eit->first+part->tick();
 
1215
        break;
 
1216
      }
 
1217
    }
 
1218
  }
 
1219
 
 
1220
  return result;
 
1221
}
 
1222
 
1198
1223
} // namespace MusECore