~ubuntu-branches/ubuntu/edgy/muse/edgy

« back to all changes in this revision

Viewing changes to muse/driver/jack.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2006-01-03 20:18:47 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060103201847-r9poqt6y5gu9hnji
Tags: 0.7.1+0.7.2pre5-1
* New upstream version.
* Updated patches:
  + [20_allow_system_timer]
    Rediffed for 0.7.2pre5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//=========================================================
2
2
//  MusE
3
3
//  Linux Music Editor
4
 
//    $Id: jack.cpp,v 1.30.2.6 2005/12/13 20:56:14 spamatica Exp $
 
4
//    $Id: jack.cpp,v 1.30.2.7 2005/12/26 21:13:21 spamatica Exp $
5
5
//  (C) Copyright 2002 Werner Schweer (ws@seh.de)
6
6
//=========================================================
7
7
 
16
16
#include "jackaudio.h"
17
17
#include "track.h"
18
18
 
19
 
// --- ENABLE DEBUG IN THIS FILE ONLY
20
 
//#define ENABLE_DEBUG
21
 
// ---
 
19
#define JACK_DEBUG 0
22
20
 
23
21
//#include "errorhandler.h"
24
22
 
31
29
#include <fst.h>
32
30
#endif
33
31
 
34
 
 
35
32
JackAudioDevice* jackAudio;
36
33
 
37
34
//bool JackAudioDevice::jackStarted = false;
83
80
 
84
81
static int processAudio(jack_nframes_t frames, void*)
85
82
      {
 
83
      if (JACK_DEBUG)
 
84
            printf("processAudio - >>>>\n");
86
85
      segmentSize = frames;
87
86
      if (audio->isRunning())
88
87
            audio->process((unsigned long)frames);
90
89
            if (debugMsg)
91
90
                 puts("jack calling when audio is disconnected!\n");
92
91
            }
 
92
      if (JACK_DEBUG)
 
93
            printf("processAudio - <<<<\n");
93
94
      return 0;
94
95
      }
95
96
 
100
101
 
101
102
static int processSync(jack_transport_state_t state, jack_position_t* pos, void*)
102
103
      {
 
104
      if (JACK_DEBUG)
 
105
            printf("processSync()\n");
 
106
      
103
107
      int audioState = Audio::STOP;
104
108
      switch (state) {
105
109
            case JackTransportStopped:   audioState = Audio::STOP;
117
121
 
118
122
static void processShutdown(void*)
119
123
      {
 
124
      if (JACK_DEBUG)
 
125
          printf("processShutdown()\n");
120
126
      //printf("processShutdown\n");
121
127
      audio->shutdown();
122
128
 
170
176
 
171
177
JackAudioDevice::~JackAudioDevice()
172
178
      {
 
179
      if (JACK_DEBUG)
 
180
            printf("~JackAudioDevice()\n");
173
181
      if (_client) {
174
182
            if (jack_client_close(_client)) {
175
183
                  //error->logError("jack_client_close() failed: %s\n", strerror(errno));
194
202
 
195
203
bool initJackAudio()
196
204
      {
 
205
      if (JACK_DEBUG)
 
206
            printf("initJackAudio()\n");
197
207
      if (debugMsg) {
198
208
            fprintf(stderr,"init Jack Audio\n");
199
209
            jack_set_error_function(jackError);
255
265
 
256
266
static int srate_callback(jack_nframes_t n, void*)
257
267
      {
258
 
      if (debugMsg)
 
268
      if (debugMsg || JACK_DEBUG)
259
269
            printf("JACK: sample rate changed: %d\n", n);
260
270
      return 0;
261
271
      }
266
276
 
267
277
static void registration_callback(jack_port_id_t, int, void*)
268
278
      {
269
 
      if (debugMsg)
 
279
      if (debugMsg || JACK_DEBUG)
270
280
            printf("JACK: registration changed\n");
271
281
      }
272
282
 
278
288
 
279
289
static int graph_callback(void*)
280
290
      {
 
291
      if (JACK_DEBUG)
 
292
            printf("graph_callback()\n");
281
293
      // we cannot call JackAudioDevice::graphChanged() from this
282
294
      // context, so we send a message to the gui thread which in turn
283
295
      // calls graphChanged()
295
307
 
296
308
void JackAudioDevice::graphChanged()
297
309
      {
 
310
      if (JACK_DEBUG)
 
311
            printf("graphChanged()\n");
298
312
      InputList* il = song->inputs();
299
313
      for (iAudioInput ii = il->begin(); ii != il->end(); ++ii) {
300
314
            AudioInput* it = *ii;
468
482
 
469
483
void JackAudioDevice::registerClient()
470
484
      {
 
485
      if (JACK_DEBUG)
 
486
            printf("registerClient()\n");
471
487
      jack_set_process_callback(_client, processAudio, 0);
472
488
      jack_set_sync_callback(_client, processSync, 0);
473
489
      jack_on_shutdown(_client, processShutdown, 0);
485
501
 
486
502
void* JackAudioDevice::registerInPort(const char* name)
487
503
      {
 
504
      if (JACK_DEBUG)
 
505
            printf("registerInPort()\n");
488
506
      void* p = jack_port_register(_client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
489
507
// printf("JACK: registerInPort: <%s> %p\n", name, p);
490
508
      return p;
496
514
 
497
515
void* JackAudioDevice::registerOutPort(const char* name)
498
516
      {
 
517
      if (JACK_DEBUG)
 
518
            printf("registerOutPort()\n");
499
519
      void* p = jack_port_register(_client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
500
520
// printf("JACK: registerOutPort: <%s> %p\n", name, p);
501
521
      return p;
507
527
 
508
528
void exitJackAudio()
509
529
      {
 
530
      if (JACK_DEBUG)
 
531
            printf("exitJackAudio()\n");
510
532
      if (jackAudio)
511
533
            delete jackAudio;
512
534
      }
517
539
 
518
540
void JackAudioDevice::connect(void* src, void* dst)
519
541
      {
 
542
      if (JACK_DEBUG)
 
543
            printf("JackAudioDevice::connect()\n");
520
544
      const char* sn = jack_port_name((jack_port_t*) src);
521
545
      const char* dn = jack_port_name((jack_port_t*) dst);
522
546
      if (sn == 0 || dn == 0) {
535
559
 
536
560
void JackAudioDevice::disconnect(void* src, void* dst)
537
561
      {
 
562
      if (JACK_DEBUG)
 
563
            printf("JackAudioDevice::disconnect()\n");
538
564
      const char* sn = jack_port_name((jack_port_t*) src);
539
565
      const char* dn = jack_port_name((jack_port_t*) dst);
540
566
      if (sn == 0 || dn == 0) {
553
579
 
554
580
void JackAudioDevice::start()
555
581
      {
 
582
      if (JACK_DEBUG)
 
583
            printf("JackAudioDevice::start()\n");
 
584
 
556
585
      doSetuid();
557
586
 
558
587
      if (jack_activate(_client)) {
604
633
 
605
634
void JackAudioDevice::stop()
606
635
      {
607
 
                        //fprintf(stderr,"JackAudioDevice::stop()\n");
 
636
      if (JACK_DEBUG)
 
637
            printf("JackAudioDevice::stop()\n");
608
638
      if (jack_deactivate(_client)) {
609
639
            fprintf (stderr, "cannot deactivate client\n");
610
640
            }
650
680
 
651
681
std::list<QString> JackAudioDevice::outputPorts()
652
682
      {
 
683
      if (JACK_DEBUG)
 
684
            printf("JackAudioDevice::outputPorts()\n");
653
685
      const char** ports = jack_get_ports(_client, 0, 0, 0);
654
686
      std::list<QString> clientList;
655
687
      for (const char** p = ports; p && *p; ++p) {
672
704
 
673
705
std::list<QString> JackAudioDevice::inputPorts()
674
706
      {
 
707
      if (JACK_DEBUG)
 
708
            printf("JackAudioDevice::inputPorts()\n");
675
709
      const char** ports = jack_get_ports(_client, 0, 0, 0);
676
710
      std::list<QString> clientList;
677
711
      for (const char** p = ports; p && *p; ++p) {
694
728
 
695
729
QString JackAudioDevice::portName(void* port)
696
730
      {
 
731
      if (JACK_DEBUG)
 
732
            printf("JackAudioDevice::portName(\n");
697
733
      if (!port) 
698
734
            return "";
699
735
      
708
744
 
709
745
void JackAudioDevice::unregisterPort(void* p)
710
746
      {
 
747
      if (JACK_DEBUG)
 
748
            printf("JackAudioDevice::unregisterPort(\n");
711
749
//      printf("JACK: unregister Port\n");
712
750
      jack_port_unregister(_client, (jack_port_t*)p);
713
751
      }
718
756
 
719
757
int JackAudioDevice::getState()
720
758
      {
 
759
      if (JACK_DEBUG)
 
760
            printf("JackAudioDevice::getState ()\n");
721
761
      transportState = jack_transport_query(_client, &pos);
722
762
      switch (transportState) {
723
763
            case JackTransportStopped:  return Audio::STOP;
735
775
 
736
776
void JackAudioDevice::setFreewheel(bool f)
737
777
      {
 
778
      if (JACK_DEBUG)
 
779
            printf("JackAudioDevice::setFreewheel(\n");
738
780
//      printf("JACK: setFreewheel %d\n", f);
739
781
      jack_set_freewheel(_client, f);
740
782
      }
745
787
 
746
788
void JackAudioDevice::startTransport()
747
789
      {
 
790
      if (JACK_DEBUG)
 
791
            printf("JackAudioDevice::startTransport()\n");
748
792
//      printf("JACK: startTransport\n");
749
793
      jack_transport_start(_client);
750
794
      }
755
799
 
756
800
void JackAudioDevice::stopTransport()
757
801
      {
758
 
//      printf("JACK: stopTransport\n");
759
 
      jack_transport_stop(_client);
 
802
      if (JACK_DEBUG)
 
803
            printf("JackAudioDevice::stopTransport()\n");
 
804
      if (transportState != JackTransportStopped) {
 
805
        //      printf("JACK: stopTransport\n");
 
806
            jack_transport_stop(_client);
 
807
            transportState=JackTransportStopped;
 
808
            }
760
809
      }
761
810
 
762
811
//---------------------------------------------------------
765
814
 
766
815
void JackAudioDevice::seekTransport(unsigned frame)
767
816
      {
 
817
      if (JACK_DEBUG)
 
818
            printf("JackAudioDevice::seekTransport(\n");
768
819
//      printf("JACK: seekTransport %d\n", frame);
769
820
      jack_transport_locate(_client, frame);
770
821
      }
775
826
 
776
827
void* JackAudioDevice::findPort(const char* name)
777
828
      {
 
829
      if (JACK_DEBUG)
 
830
            printf("JackAudioDevice::findPort(\n");
778
831
      void* p = jack_port_by_name(_client, name);
779
832
// printf("Jack::findPort <%s>, %p\n", name, p);
780
833
      return p;