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

« back to all changes in this revision

Viewing changes to muse/audio.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-11-17 21:43:38 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101117214338-1hvfl7oo2dsqnvrb
Tags: 1.1-0ubuntu1
* New upstream release (LP: #668631)
* Switch to dpkg-source 3.0 (quilt) format
* Switch to dh7 short form
* debian/rules:
  - added --enable-dssi and --enable-osc to conf flags for dssi support
  - added -ljackserver to LDFLAGS to fix a FTBFS because of --as-needed
* debian/control:
  - added build build dependency on liblo-dev and dssi-dev for dssi support
  - bump Standards-version to 3.9.1. No changes required.
* debian/muse.desktop, debian/muse.xpm: dropped as desktop file and icon is
  now shipped upstream.
* fix-desktop-categories.patch: fix Categories tag in upstream desktop file
* 10_es_locale_fix.dpatch: refreshed and converted to quilt as
  fix_es_locale.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
Audio* audio;
36
36
AudioDevice* audioDevice;   // current audio device in use
37
37
 
38
 
static const unsigned char mmcDeferredPlayMsg[] = { 0x7f, 0x7f, 0x06, 0x03 };
39
 
static const unsigned char mmcStopMsg[] =         { 0x7f, 0x7f, 0x06, 0x01 };
 
38
// p3.3.25
 
39
extern unsigned int volatile midiExtSyncTicks;
 
40
 
 
41
 
 
42
//static const unsigned char mmcDeferredPlayMsg[] = { 0x7f, 0x7f, 0x06, 0x03 };
 
43
//static const unsigned char mmcStopMsg[] =         { 0x7f, 0x7f, 0x06, 0x01 };
40
44
 
41
45
const char* seqMsgList[] = {
42
46
      "SEQM_ADD_TRACK", "SEQM_REMOVE_TRACK", "SEQM_CHANGE_TRACK", "SEQM_MOVE_TRACK",
227
231
 
228
232
bool Audio::sync(int jackState, unsigned frame)
229
233
      {
230
 
      // Added by Tim. p3.3.20
231
 
      if(debugMsg)
232
 
        printf("Audio::sync state %s jackState %s frame %d\n", audioStates[state], audioStates[jackState], frame);
233
234
      
 
235
// Changed by Tim. p3.3.24
 
236
/*      
234
237
      bool done = true;
235
238
      if (state == LOOP1) 
236
239
            state = LOOP2;
245
248
                  done = audioPrefetch->seekDone();
246
249
            }
247
250
      
248
 
      // Added by Tim. p3.3.20
249
 
      //if(debugMsg)
250
 
      //  printf("Audio::sync done:%d state %s\n", done, audioStates[state]);
 
251
      return done;
 
252
*/      
 
253
      bool done = true;
 
254
      if (state == LOOP1)
 
255
            state = LOOP2;
 
256
      else {
 
257
            State s = State(jackState);
 
258
            //
 
259
            //  STOP -> START_PLAY      start rolling
 
260
            //  STOP -> STOP            seek in stop state
 
261
            //  PLAY -> START_PLAY  seek in play state
 
262
 
 
263
            if (state != START_PLAY) {
 
264
                //Pos p(frame, AL::FRAMES);
 
265
                //    seek(p);
 
266
                Pos p(frame, false);
 
267
                seek(p);
 
268
              if (!_freewheel)
 
269
                      done = audioPrefetch->seekDone();
 
270
                if (s == START_PLAY)
 
271
                        state = START_PLAY;
 
272
                }
 
273
            else {
 
274
                //if (frame != _seqTime.pos.frame()) {
 
275
                if (frame != _pos.frame()) {
 
276
                        // seek during seek
 
277
                            //seek(Pos(frame, AL::FRAMES));
 
278
                            seek(Pos(frame, false));
 
279
                        }
 
280
                done = audioPrefetch->seekDone();
 
281
                  }
 
282
            }
 
283
      return done;
251
284
      
252
 
      return done;
253
285
      }
254
286
 
255
287
//---------------------------------------------------------
307
339
 
308
340
      int jackState = audioDevice->getState();
309
341
 
310
 
      // Added by Tim. p3.3.20
311
342
      //if(debugMsg)
312
343
      //  printf("Audio::process Current state:%s jackState:%s\n", audioStates[state], audioStates[jackState]);
313
344
      
324
355
            startRolling();
325
356
            }
326
357
      else if (isPlaying() && jackState == STOP) {
 
358
            // p3.3.43 Make sure to stop bounce and freewheel mode, for example if user presses stop 
 
359
            //  in QJackCtl before right-hand marker is reached (which is handled below).
 
360
            //printf("Audio::process isPlaying() && jackState == STOP\n");
 
361
            //if (_bounce) 
 
362
            //{
 
363
              //printf("  stopping bounce...\n");
 
364
            //  _bounce = false;
 
365
            //  write(sigFd, "F", 1);
 
366
            //}
 
367
            
327
368
            stopRolling();
328
369
            }
329
370
      else if (state == START_PLAY && jackState == STOP) {
382
423
               && !(song->record()
383
424
                || _bounce
384
425
                || song->loop())) {
385
 
                  // Added by Tim. p3.3.20
386
426
                  //if(debugMsg)
387
427
                  //  printf("Audio::process curTickPos >= song->len\n");
388
428
                  
428
468
// printf("  process: seek to %d, end %d\n", _loopFrame, loop.frame());
429
469
                        }
430
470
                  }
431
 
            Pos ppp(_pos);
432
 
            ppp += frames;
433
 
            nextTickPos = ppp.tick();
434
 
            }
 
471
            
 
472
            
 
473
            // p3.3.25
 
474
            if(extSyncFlag.value())
 
475
            {
 
476
              nextTickPos = curTickPos + midiExtSyncTicks;
 
477
              // Probably not good - interfere with midi thread.
 
478
              midiExtSyncTicks = 0;
 
479
            }
 
480
            else
 
481
            {
 
482
              
 
483
              Pos ppp(_pos);
 
484
              ppp += frames;
 
485
              nextTickPos = ppp.tick();
 
486
            }
 
487
          }
435
488
      //
436
489
      // resync with audio interface
437
490
      //
439
492
      syncTime    = curTime();
440
493
      frameOffset = syncFrame - samplePos;
441
494
 
442
 
      // Added by Tim. p3.3.13
443
495
      //printf("Audio::process calling process1:\n");
444
496
      
445
497
      process1(samplePos, offset, frames);
548
600
          float data[frames * channels];
549
601
          for (int i = 0; i < channels; ++i)
550
602
                buffer[i] = data + i * frames;
551
 
          // Added by Tim. p3.3.13
552
603
          //printf("Audio::process1 calling track->copyData for track:%s\n", track->name().latin1());
553
604
      
554
 
          track->copyData(samplePos, channels, frames, buffer);
 
605
          // p3.3.38
 
606
          //track->copyData(samplePos, channels, frames, buffer);
 
607
          track->copyData(samplePos, channels, -1, -1, frames, buffer);
555
608
        }
556
609
      }      
557
610
    }
591
644
                  msg->snode->addPlugin(msg->plugin, msg->ival);
592
645
                  break;
593
646
            case AUDIO_SET_PLUGIN_CTRL_VAL:
594
 
                  msg->plugin->track()->setPluginCtrlVal(msg->ival, msg->dval);
 
647
                  //msg->plugin->track()->setPluginCtrlVal(msg->ival, msg->dval);
 
648
                  // p3.3.43
 
649
                  msg->snode->setPluginCtrlVal(msg->ival, msg->dval);
595
650
                  break;
596
651
            case AUDIO_SWAP_CONTROLLER_IDX:
597
652
                  msg->snode->swapControllerIDX(msg->a, msg->b);
719
774
void Audio::seek(const Pos& p)
720
775
      {
721
776
      if (_pos == p) {
722
 
            printf("seek: already there\n");
723
 
            return;
 
777
            if(debugMsg)
 
778
              printf("Audio::seek already there\n");
 
779
            return;        
724
780
            }
725
781
      
 
782
            // p3.3.23
 
783
            //printf("Audio::seek frame:%d\n", p.frame());
726
784
      _pos        = p;
727
785
      if (!checkAudioDevice()) return;
728
786
      syncFrame   = audioDevice->framePos();
731
789
 
732
790
      midiSeq->msgSeek();     // handle stuck notes and set
733
791
                              // controller for new position
734
 
      //if(genMCSync) 
735
 
      //{
 
792
      
 
793
      // p3.3.31
 
794
      // Don't send if external sync is on. The master, and our sync routing system will take care of that.
 
795
      if(!extSyncFlag.value())
 
796
      {
 
797
        
736
798
        for(int port = 0; port < MIDI_PORTS; ++port) 
737
799
        {
738
800
          MidiPort* mp = &midiPorts[port];
739
801
          MidiDevice* dev = mp->device();
740
 
          if(!dev || !mp->syncInfo().MCOut())
 
802
          //if(!dev || !mp->syncInfo().MCOut())
 
803
          if(!dev || !mp->syncInfo().MRTOut())
741
804
            continue;
742
805
            
743
806
          // Added by T356: Shall we check for device write open flag to see if it's ok to send?...
768
831
          if(isPlaying)
769
832
            mp->sendContinue();
770
833
        }
771
 
      //}
 
834
      }
772
835
        
773
836
      /*
774
837
      if(genMCSync) 
893
956
      state = PLAY;
894
957
      write(sigFd, "1", 1);   // Play
895
958
 
896
 
      // Changed by Tim. p3.3.6
897
 
      //if (genMMC)
898
 
      //    midiPorts[txSyncPort].sendSysex(mmcDeferredPlayMsg, sizeof(mmcDeferredPlayMsg));
899
 
      //if (genMCSync) {
900
 
      //      if (curTickPos)
901
 
      //            midiPorts[txSyncPort].sendContinue();
902
 
      //      else
903
 
      //            midiPorts[txSyncPort].sendStart();
904
 
      //      }
905
 
      for(int port = 0; port < MIDI_PORTS; ++port) 
 
959
      // p3.3.31
 
960
      // Don't send if external sync is on. The master, and our sync routing system will take care of that.
 
961
      if(!extSyncFlag.value())
906
962
      {
907
 
        MidiPort* mp = &midiPorts[port];
908
 
        MidiDevice* dev = mp->device();
909
 
        if(!dev)
910
 
          continue;
 
963
        
 
964
        // Changed by Tim. p3.3.6
 
965
        //if (genMMC)
 
966
        //    midiPorts[txSyncPort].sendSysex(mmcDeferredPlayMsg, sizeof(mmcDeferredPlayMsg));
 
967
        //if (genMCSync) {
 
968
        //      if (curTickPos)
 
969
        //            midiPorts[txSyncPort].sendContinue();
 
970
        //      else
 
971
        //            midiPorts[txSyncPort].sendStart();
 
972
        //      }
 
973
        for(int port = 0; port < MIDI_PORTS; ++port) 
 
974
        {
 
975
          MidiPort* mp = &midiPorts[port];
 
976
          MidiDevice* dev = mp->device();
 
977
          if(!dev)
 
978
            continue;
 
979
              
 
980
          // Shall we check open flags?
 
981
          //if(!(dev->rwFlags() & 0x1) || !(dev->openFlags() & 1))
 
982
          //if(!(dev->openFlags() & 1))
 
983
          //  continue;
 
984
          
 
985
          MidiSyncInfo& si = mp->syncInfo();
911
986
            
912
 
        // Shall we check open flags?
913
 
        //if(!(dev->rwFlags() & 0x1) || !(dev->openFlags() & 1))
914
 
        //if(!(dev->openFlags() & 1))
915
 
        //  continue;
916
 
        
917
 
        MidiSyncInfo& si = mp->syncInfo();
 
987
          //if(genMMC && si.MMCOut())
 
988
          if(si.MMCOut())
 
989
            //mp->sendSysex(mmcDeferredPlayMsg, sizeof(mmcDeferredPlayMsg));
 
990
            mp->sendMMCDeferredPlay();
918
991
          
919
 
        //if(genMMC && si.MMCOut())
920
 
        if(si.MMCOut())
921
 
          mp->sendSysex(mmcDeferredPlayMsg, sizeof(mmcDeferredPlayMsg));
922
 
        
923
 
        //if(genMCSync && si.MCOut())
924
 
        if(si.MCOut())
925
 
        {
926
 
          if(curTickPos)
927
 
            mp->sendContinue();
928
 
          else
929
 
            mp->sendStart();
930
 
        }  
931
 
      }
 
992
          //if(genMCSync && si.MCOut())
 
993
          //if(si.MCOut())
 
994
          if(si.MRTOut())
 
995
          {
 
996
            if(curTickPos)
 
997
              mp->sendContinue();
 
998
            else
 
999
              mp->sendStart();
 
1000
          }  
 
1001
        }
 
1002
      }  
932
1003
      
933
1004
      /*
934
1005
      for(iMidiDevice imd = midiDevices.begin(); imd != midiDevices.end(); ++imd) 
1037
1108
                  }
1038
1109
              }
1039
1110
          }
 
1111
     
 
1112
     //tempomap.clearExtTempoList();     
1040
1113
     }
1041
1114
 
1042
1115
//---------------------------------------------------------
1074
1147
        }
1075
1148
 
1076
1149
#endif
1077
 
      // Changed by Tim. p3.3.6
1078
 
      //MidiPort* syncPort = &midiPorts[txSyncPort];
1079
 
      //if (genMMC) {
1080
 
      //      unsigned char mmcPos[] = {
1081
 
      //            0x7f, 0x7f, 0x06, 0x44, 0x06, 0x01,
1082
 
      //            0, 0, 0, 0, 0
1083
 
      //            };
1084
 
      //      int frame = tempomap.tick2frame(curTickPos);
1085
 
      //      MTC mtc(double(frame) / double(sampleRate));
1086
 
      //      mmcPos[6] = mtc.h() | (mtcType << 5);
1087
 
      //      mmcPos[7] = mtc.m();
1088
 
      //      mmcPos[8] = mtc.s();
1089
 
      //      mmcPos[9] = mtc.f();
1090
 
      //      mmcPos[10] = mtc.sf();
1091
 
      //      syncPort->sendSysex(mmcStopMsg, sizeof(mmcStopMsg));
1092
 
      //      syncPort->sendSysex(mmcPos, sizeof(mmcPos));
1093
 
      //      }
1094
 
      //if (genMCSync) {         // Midi Clock
 
1150
      
 
1151
      // p3.3.31
 
1152
      // Don't send if external sync is on. The master, and our sync routing system will take care of that.
 
1153
      if(!extSyncFlag.value())
 
1154
      {
 
1155
        
 
1156
        // Changed by Tim. p3.3.6
 
1157
        //MidiPort* syncPort = &midiPorts[txSyncPort];
 
1158
        //if (genMMC) {
 
1159
        //      unsigned char mmcPos[] = {
 
1160
        //            0x7f, 0x7f, 0x06, 0x44, 0x06, 0x01,
 
1161
        //            0, 0, 0, 0, 0
 
1162
        //            };
 
1163
        //      int frame = tempomap.tick2frame(curTickPos);
 
1164
        //      MTC mtc(double(frame) / double(sampleRate));
 
1165
        //      mmcPos[6] = mtc.h() | (mtcType << 5);
 
1166
        //      mmcPos[7] = mtc.m();
 
1167
        //      mmcPos[8] = mtc.s();
 
1168
        //      mmcPos[9] = mtc.f();
 
1169
        //      mmcPos[10] = mtc.sf();
 
1170
        //      syncPort->sendSysex(mmcStopMsg, sizeof(mmcStopMsg));
 
1171
        //      syncPort->sendSysex(mmcPos, sizeof(mmcPos));
 
1172
        //      }
 
1173
        //if (genMCSync) {         // Midi Clock
 
1174
              // send STOP and
 
1175
              // "set song position pointer"
 
1176
        //      syncPort->sendStop();
 
1177
        //      syncPort->sendSongpos(curTickPos * 4 / config.division);
 
1178
        //      }
 
1179
        for(int port = 0; port < MIDI_PORTS; ++port) 
 
1180
        {
 
1181
          MidiPort* mp = &midiPorts[port];
 
1182
          MidiDevice* dev = mp->device();
 
1183
          if(!dev)
 
1184
            continue;
 
1185
              
 
1186
          // Shall we check open flags?
 
1187
          //if(!(dev->rwFlags() & 0x1) || !(dev->openFlags() & 1))
 
1188
          //if(!(dev->openFlags() & 1))
 
1189
          //  continue;
 
1190
          
 
1191
          MidiSyncInfo& si = mp->syncInfo();
 
1192
            
 
1193
          //if(genMMC && si.MMCOut())
 
1194
          if(si.MMCOut())
 
1195
          {
 
1196
            //unsigned char mmcPos[] = {
 
1197
            //      0x7f, 0x7f, 0x06, 0x44, 0x06, 0x01,
 
1198
            //      0, 0, 0, 0, 0
 
1199
            //      };
 
1200
  
 
1201
            // p3.3.31
 
1202
            /*
 
1203
            int frame = tempomap.tick2frame(curTickPos);
 
1204
            MTC mtc(double(frame) / double(sampleRate));
 
1205
            */          
 
1206
            
 
1207
            //mmcPos[6] = mtc.h() | (mtcType << 5);
 
1208
            //mmcPos[7] = mtc.m();
 
1209
            //mmcPos[8] = mtc.s();
 
1210
            //mmcPos[9] = mtc.f();
 
1211
            //mmcPos[10] = mtc.sf();
 
1212
            
 
1213
            //mp->sendSysex(mmcStopMsg, sizeof(mmcStopMsg));
 
1214
            mp->sendMMCStop();
 
1215
            //mp->sendSysex(mmcPos, sizeof(mmcPos));
 
1216
            
 
1217
            // p3.3.31
 
1218
            // Added check of option send continue not start.
 
1219
            // Hmm, is this required? Seems to make other devices unhappy.
 
1220
            /*
 
1221
            if(!si.sendContNotStart())
 
1222
              mp->sendMMCLocate(mtc.h() | (mtcType << 5), 
 
1223
                              mtc.m(), mtc.s(), mtc.f(), mtc.sf());
 
1224
            */                  
 
1225
            
 
1226
          }
 
1227
        
 
1228
          //if(genMCSync && si.MCOut()) // Midi Clock
 
1229
          //if(si.MCOut()) // Midi Clock
 
1230
          if(si.MRTOut()) // 
 
1231
          {
1095
1232
            // send STOP and
1096
1233
            // "set song position pointer"
1097
 
      //      syncPort->sendStop();
1098
 
      //      syncPort->sendSongpos(curTickPos * 4 / config.division);
1099
 
      //      }
1100
 
      for(int port = 0; port < MIDI_PORTS; ++port) 
1101
 
      {
1102
 
        MidiPort* mp = &midiPorts[port];
1103
 
        MidiDevice* dev = mp->device();
1104
 
        if(!dev)
1105
 
          continue;
1106
 
            
1107
 
        // Shall we check open flags?
1108
 
        //if(!(dev->rwFlags() & 0x1) || !(dev->openFlags() & 1))
1109
 
        //if(!(dev->openFlags() & 1))
1110
 
        //  continue;
1111
 
        
1112
 
        MidiSyncInfo& si = mp->syncInfo();
1113
 
          
1114
 
        //if(genMMC && si.MMCOut())
1115
 
        if(si.MMCOut())
1116
 
        {
1117
 
          unsigned char mmcPos[] = {
1118
 
                0x7f, 0x7f, 0x06, 0x44, 0x06, 0x01,
1119
 
                0, 0, 0, 0, 0
1120
 
                };
1121
 
          int frame = tempomap.tick2frame(curTickPos);
1122
 
          MTC mtc(double(frame) / double(sampleRate));
1123
 
          mmcPos[6] = mtc.h() | (mtcType << 5);
1124
 
          mmcPos[7] = mtc.m();
1125
 
          mmcPos[8] = mtc.s();
1126
 
          mmcPos[9] = mtc.f();
1127
 
          mmcPos[10] = mtc.sf();
1128
 
          
1129
 
          mp->sendSysex(mmcStopMsg, sizeof(mmcStopMsg));
1130
 
          mp->sendSysex(mmcPos, sizeof(mmcPos));
1131
 
        }
1132
 
      
1133
 
        //if(genMCSync && si.MCOut()) // Midi Clock
1134
 
        if(si.MCOut()) // Midi Clock
1135
 
        {
1136
 
          // send STOP and
1137
 
          // "set song position pointer"
1138
 
          mp->sendStop();
1139
 
          mp->sendSongpos(curTickPos * 4 / config.division);
 
1234
            mp->sendStop();
 
1235
            
 
1236
            // p3.3.31
 
1237
            // Added check of option send continue not start.
 
1238
            // Hmm, is this required? Seems to make other devices unhappy.
 
1239
            /*
 
1240
            if(!si.sendContNotStart())
 
1241
              mp->sendSongpos(curTickPos * 4 / config.division);
 
1242
            */  
 
1243
            
 
1244
          }
1140
1245
        }
1141
1246
      }
1142
1247
      
1143
 
      
1144
1248
      /*
1145
1249
      for(iMidiDevice imd = midiDevices.begin(); imd != midiDevices.end(); ++imd) 
1146
1250
      {