diff options
author | Florian Jung <flo@windfisch.org> | 2012-05-28 14:15:52 +0000 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2012-05-28 14:15:52 +0000 |
commit | d2a88cfaad5ac385fc3c6212c09ad7fbc38e9454 (patch) | |
tree | 387da0b38255003e1a971629ea0de32273ac3d3c /muse2/muse/driver | |
parent | 716f5a5b56a3b7ff59004ef0a1af5f98cb2a691c (diff) |
merged with release_2_0
Diffstat (limited to 'muse2/muse/driver')
-rw-r--r-- | muse2/muse/driver/alsamidi.cpp | 47 | ||||
-rw-r--r-- | muse2/muse/driver/alsamidi.h | 1 | ||||
-rw-r--r-- | muse2/muse/driver/alsatimer.cpp | 29 | ||||
-rw-r--r-- | muse2/muse/driver/audiodev.h | 3 | ||||
-rw-r--r-- | muse2/muse/driver/dummyaudio.cpp | 11 | ||||
-rw-r--r-- | muse2/muse/driver/jack.cpp | 81 | ||||
-rw-r--r-- | muse2/muse/driver/jackaudio.h | 3 | ||||
-rw-r--r-- | muse2/muse/driver/rtctimer.cpp | 20 |
8 files changed, 136 insertions, 59 deletions
diff --git a/muse2/muse/driver/alsamidi.cpp b/muse2/muse/driver/alsamidi.cpp index 08f5345f..f75b9c33 100644 --- a/muse2/muse/driver/alsamidi.cpp +++ b/muse2/muse/driver/alsamidi.cpp @@ -42,6 +42,10 @@ #include <QApplication> +// Enable debugging: +//#define ALSA_DEBUG 1 + + namespace MusECore { static int alsaSeqFdi = -1; @@ -98,7 +102,9 @@ QString MidiAlsaDevice::open() int cap = snd_seq_port_info_get_capability(pinfo); - //printf("MidiAlsaDevice::open cap:%d\n", cap); +#ifdef ALSA_DEBUG + printf("MidiAlsaDevice::open cap:%d\n", cap); +#endif // subscribe for writing if (_openFlags & 1) @@ -175,7 +181,9 @@ void MidiAlsaDevice::close() int cap = snd_seq_port_info_get_capability(pinfo); - //printf("MidiAlsaDevice::close cap:%d\n", cap); +#ifdef ALSA_DEBUG + printf("MidiAlsaDevice::close cap:%d\n", cap); +#endif // This function appears to be called only by MidiPort::setMidiDevice(), // which closes then opens the device. @@ -434,6 +442,10 @@ bool MidiAlsaDevice::putEvent(snd_seq_event_t* event) { int error; +#ifdef ALSA_DEBUG + printf("MidiAlsaDevice::putEvent\n"); +#endif + do { error = snd_seq_event_output_direct(alsaSeq, event); int len = snd_seq_event_length(event); @@ -860,9 +872,10 @@ bool initMidiAlsa() snd_strerror(error)); return true; } + const int inCap = SND_SEQ_PORT_CAP_SUBS_READ; const int outCap = SND_SEQ_PORT_CAP_SUBS_WRITE; - + snd_seq_client_info_t *cinfo; snd_seq_client_info_alloca(&cinfo); snd_seq_client_info_set_client(cinfo, -1); @@ -955,7 +968,11 @@ bool initMidiAlsa() //snd_seq_set_client_name(alsaSeq, "MusE Sequencer"); - snd_seq_set_client_name(alsaSeq, MusEGlobal::audioDevice->clientName()); + error = snd_seq_set_client_name(alsaSeq, MusEGlobal::audioDevice->clientName()); + if (error < 0) { + printf("Alsa: Set client name failed: %s", snd_strerror(error)); + return true; + } int ci = snd_seq_poll_descriptors_count(alsaSeq, POLLIN); int co = snd_seq_poll_descriptors_count(alsaSeq, POLLOUT); @@ -1045,6 +1062,24 @@ void exitMidiAlsa() } +//--------------------------------------------------------- +// setAlsaClientName +//--------------------------------------------------------- + +void setAlsaClientName(const char* name) +{ +#ifdef ALSA_DEBUG + printf("setAlsaClientName: %s seq:%p\n", name, alsaSeq); +#endif + + if(!alsaSeq) + return; + + int error = snd_seq_set_client_name(alsaSeq, name); + if (error < 0) + printf("setAlsaClientName: failed: %s", snd_strerror(error)); +} + struct AlsaPort { snd_seq_addr_t adr; char* name; @@ -1064,7 +1099,9 @@ static std::list<AlsaPort> portList; void alsaScanMidiPorts() { -// printf("alsa scan midi ports\n"); +#ifdef ALSA_DEBUG + printf("alsa scan midi ports\n"); +#endif const int inCap = SND_SEQ_PORT_CAP_SUBS_READ; const int outCap = SND_SEQ_PORT_CAP_SUBS_WRITE; diff --git a/muse2/muse/driver/alsamidi.h b/muse2/muse/driver/alsamidi.h index 7a1ac1c2..97d57f2b 100644 --- a/muse2/muse/driver/alsamidi.h +++ b/muse2/muse/driver/alsamidi.h @@ -82,6 +82,7 @@ extern int alsaSelectRfd(); extern int alsaSelectWfd(); extern void alsaProcessMidiInput(); extern void alsaScanMidiPorts(); +extern void setAlsaClientName(const char*); } // namespace MusECore diff --git a/muse2/muse/driver/alsatimer.cpp b/muse2/muse/driver/alsatimer.cpp index 20f7ab88..cf211a2f 100644 --- a/muse2/muse/driver/alsatimer.cpp +++ b/muse2/muse/driver/alsatimer.cpp @@ -1,12 +1,12 @@ - //========================================================= - // MusE - // Linux Music Editor - // $Id: alsatimer.cpp,v 1.1.2.9 2009/03/28 01:46:10 terminator356 Exp $ - // - // Plenty of code borrowed from timer.c example in - // alsalib 1.0.7 - // - // (C) Copyright 2004 Robert Jonsson (rj@spamatica.se) +//========================================================= +// MusE +// Linux Music Editor +// $Id: alsatimer.cpp,v 1.1.2.9 2009/03/28 01:46:10 terminator356 Exp $ +// +// Plenty of code borrowed from timer.c example in +// alsalib 1.0.7 +// +// (C) Copyright 2004 Robert Jonsson (rj@spamatica.se) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -22,10 +22,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // - //========================================================= +//========================================================= - #include "alsatimer.h" - #include <climits> +#include "alsatimer.h" +#include <climits> #define TIMER_DEBUG 0 @@ -73,7 +73,7 @@ namespace MusECore { int max_ids = sizeof(test_ids) / sizeof(int); long best_res = LONG_MAX; //int best_dev = -1; // SND_TIMER_GLOBAL_SYSTEM; - int best_dev = SND_TIMER_GLOBAL_SYSTEM; // p3.3.51 + int best_dev = SND_TIMER_GLOBAL_SYSTEM; int i; if (id || info || params) { @@ -107,14 +107,13 @@ namespace MusECore { device = best_dev; } - // p3.3.51 Removed. //if(best_dev==-1) // return -1; // no working timer found sprintf(timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i", devclass, sclass, card, device, subdevice); if ((err = snd_timer_open(&handle, timername, SND_TIMER_OPEN_NONBLOCK))<0) { fprintf(stderr, "AlsaTimer::initTimer(): timer open %i (%s)\n", err, snd_strerror(err)); - return -1; // p3.3.51 + return -1; } if ((err = snd_timer_info(handle, info)) < 0) { diff --git a/muse2/muse/driver/audiodev.h b/muse2/muse/driver/audiodev.h index 14fb60b3..08d6a9f0 100644 --- a/muse2/muse/driver/audiodev.h +++ b/muse2/muse/driver/audiodev.h @@ -52,6 +52,7 @@ class AudioDevice { virtual void stop () = 0; virtual int framePos() const = 0; virtual unsigned frameTime() const = 0; + virtual double systemTime() const = 0; virtual float* getBuffer(void* port, unsigned long nframes) = 0; @@ -75,7 +76,7 @@ class AudioDevice { virtual void* findPort(const char* name) = 0; virtual QString portName(void* port) = 0; virtual int getState() = 0; - virtual unsigned getCurFrame() = 0; + virtual unsigned getCurFrame() const = 0; virtual bool isRealtime() = 0; virtual int realtimePriority() const = 0; // return zero if not realtime virtual void startTransport() = 0; diff --git a/muse2/muse/driver/dummyaudio.cpp b/muse2/muse/driver/dummyaudio.cpp index 1738027d..21bb425f 100644 --- a/muse2/muse/driver/dummyaudio.cpp +++ b/muse2/muse/driver/dummyaudio.cpp @@ -27,6 +27,8 @@ #include <stdarg.h> #include <pthread.h> #include <sys/poll.h> +#include <sys/time.h> +#include <unistd.h> #include "config.h" #include "audio.h" @@ -137,7 +139,7 @@ class DummyAudioDevice : public AudioDevice { // if(DEBUG_DUMMY) // printf("DummyAudioDevice::getState %d\n", state); return state; } - virtual unsigned getCurFrame() { + virtual unsigned getCurFrame() const { if(DEBUG_DUMMY) printf("DummyAudioDevice::getCurFrame %d\n", _framePos); @@ -145,6 +147,13 @@ class DummyAudioDevice : public AudioDevice { virtual unsigned frameTime() const { return lrint(curTime() * MusEGlobal::sampleRate); } + virtual double systemTime() const + { + struct timeval t; + gettimeofday(&t, 0); + //printf("%ld %ld\n", t.tv_sec, t.tv_usec); // Note I observed values coming out of order! Causing some problems. + return (double)((double)t.tv_sec + (t.tv_usec / 1000000.0)); + } virtual bool isRealtime() { return realtimeFlag; } //virtual int realtimePriority() const { return 40; } virtual int realtimePriority() const { return _realTimePriority; } diff --git a/muse2/muse/driver/jack.cpp b/muse2/muse/driver/jack.cpp index a52410e9..4cc8bfb8 100644 --- a/muse2/muse/driver/jack.cpp +++ b/muse2/muse/driver/jack.cpp @@ -50,7 +50,7 @@ #include "jackmidi.h" -#define JACK_DEBUG 0 +#define JACK_DEBUG 0 //#include "errorhandler.h" @@ -103,6 +103,8 @@ inline bool checkJackClient(jack_client_t* _client) static void jack_thread_init (void* ) { + if (JACK_DEBUG) + printf("jack_thread_init()\n"); MusEGlobal::doSetuid(); #ifdef VST_SUPPORT if (loadVST) @@ -240,7 +242,8 @@ static void timebase_callback(jack_transport_state_t /* state */, int /* new_pos */, void*) { - //printf("Jack timebase_callback pos->frame:%u MusEGlobal::audio->tickPos:%d MusEGlobal::song->cpos:%d\n", pos->frame, MusEGlobal::audio->tickPos(), MusEGlobal::song->cpos()); + if (JACK_DEBUG) + printf("Jack timebase_callback pos->frame:%u MusEGlobal::audio->tickPos:%d MusEGlobal::song->cpos:%d\n", pos->frame, MusEGlobal::audio->tickPos(), MusEGlobal::song->cpos()); //Pos p(pos->frame, false); Pos p(MusEGlobal::extSyncFlag.value() ? MusEGlobal::audio->tickPos() : pos->frame, MusEGlobal::extSyncFlag.value() ? true : false); @@ -320,6 +323,7 @@ static void jackError(const char *s) static void noJackError(const char* /* s */) { + //printf("noJackError()\n"); } //--------------------------------------------------------- @@ -428,26 +432,25 @@ bool initJackAudio() if (MusEGlobal::debugMsg) fprintf(stderr, "initJackAudio(): client %s opened.\n", jack_get_client_name(client)); - if (client) { - jack_set_error_function(jackError); - //jackAudio = new JackAudioDevice(client, jackIdString); - jackAudio = new JackAudioDevice(client, jack_get_client_name(client)); - if (MusEGlobal::debugMsg) - fprintf(stderr, "initJackAudio(): registering client...\n"); - jackAudio->registerClient(); - MusEGlobal::sampleRate = jack_get_sample_rate(client); - MusEGlobal::segmentSize = jack_get_buffer_size(client); - jack_set_thread_init_callback(client, (JackThreadInitCallback) jack_thread_init, 0); - //jack_set_timebase_callback(client, 0, (JackTimebaseCallback) timebase_callback, 0); - } + //jack_set_error_function(jackError); + //jackAudio = new JackAudioDevice(client, jackIdString); + jackAudio = new JackAudioDevice(client, jack_get_client_name(client)); + if (MusEGlobal::debugMsg) + fprintf(stderr, "initJackAudio(): registering client...\n"); + MusEGlobal::undoSetuid(); - if (client) { - MusEGlobal::audioDevice = jackAudio; - jackAudio->scanMidiPorts(); - return false; - } - return true; + MusEGlobal::audioDevice = jackAudio; + + // WARNING Don't do this here. Do it after any MusE ALSA client is registered, otherwise random crashes can occur. + //jackAudio->registerClient(); + + MusEGlobal::sampleRate = jack_get_sample_rate(client); + MusEGlobal::segmentSize = jack_get_buffer_size(client); + + jackAudio->scanMidiPorts(); + + return false; } static int bufsize_callback(jack_nframes_t n, void*) @@ -1017,6 +1020,9 @@ void JackAudioDevice::registerClient() if (JACK_DEBUG) printf("registerClient()\n"); if(!checkJackClient(_client)) return; + + jack_set_thread_init_callback(_client, (JackThreadInitCallback) jack_thread_init, 0); + //jack_set_timebase_callback(client, 0, (JackTimebaseCallback) timebase_callback, 0); jack_set_process_callback(_client, processAudio, 0); jack_set_sync_callback(_client, processSync, 0); //jack_set_sync_timeout(_client, 5000000); // Change default 2 to 5 second sync timeout because prefetch may be very slow esp. with resampling ! @@ -1220,10 +1226,33 @@ jack_transport_state_t JackAudioDevice::transportQuery(jack_position_t* pos) } //--------------------------------------------------------- +// systemTime +// Return system time. Depends on selected clock source. +// With Jack, may be based upon wallclock time, the +// processor cycle counter or the HPET clock etc. +//--------------------------------------------------------- + +double JackAudioDevice::systemTime() const +{ + // Client valid? According to sletz: For jack_get_time "There are some timing related + // initialization that are done once when a first client is created." + if(!checkJackClient(_client)) + { + struct timeval t; + gettimeofday(&t, 0); + //printf("%ld %ld\n", t.tv_sec, t.tv_usec); // Note I observed values coming out of order! Causing some problems. + return (double)((double)t.tv_sec + (t.tv_usec / 1000000.0)); + } + + jack_time_t t = jack_get_time(); + return double(t) / 1000000.0; +} + +//--------------------------------------------------------- // getCurFrame //--------------------------------------------------------- -unsigned int JackAudioDevice::getCurFrame() +unsigned int JackAudioDevice::getCurFrame() const { if (JACK_DEBUG) printf("JackAudioDevice::getCurFrame pos.frame:%d\n", pos.frame); @@ -1430,8 +1459,8 @@ std::list<QString> JackAudioDevice::inputPorts(bool midi, int aliases) QString JackAudioDevice::portName(void* port) { - if (JACK_DEBUG) - printf("JackAudioDevice::portName(\n"); + //if (JACK_DEBUG) + // printf("JackAudioDevice::portName\n"); if(!checkJackClient(_client)) return ""; if (!port) return ""; @@ -1683,8 +1712,8 @@ int JackAudioDevice::setMaster(bool f) void JackAudioDevice::scanMidiPorts() { - if(MusEGlobal::debugMsg) - printf("JackAudioDevice::scanMidiPorts:\n"); + //if(MusEGlobal::debugMsg) + // printf("JackAudioDevice::scanMidiPorts:\n"); /* const char* type = JACK_DEFAULT_MIDI_TYPE; @@ -1833,7 +1862,7 @@ void exitJackAudio() if (JACK_DEBUG) printf("exitJackAudio() after delete jackAudio\n"); - MusEGlobal::audioDevice = NULL; // By Tim + MusEGlobal::audioDevice = NULL; } } // namespace MusECore diff --git a/muse2/muse/driver/jackaudio.h b/muse2/muse/driver/jackaudio.h index 838a20df..9640ca81 100644 --- a/muse2/muse/driver/jackaudio.h +++ b/muse2/muse/driver/jackaudio.h @@ -71,6 +71,7 @@ class JackAudioDevice : public AudioDevice { virtual int framePos() const; virtual unsigned frameTime() const { return _frameCounter; } + virtual double systemTime() const; virtual float* getBuffer(void* port, unsigned long nframes) { return (float*)jack_port_get_buffer((jack_port_t*)port, nframes); @@ -95,7 +96,7 @@ class JackAudioDevice : public AudioDevice { virtual void* findPort(const char* name); virtual QString portName(void* port); virtual int getState(); - virtual unsigned int getCurFrame(); + virtual unsigned int getCurFrame() const; virtual bool isRealtime() { return jack_is_realtime(_client); } virtual int realtimePriority() const; virtual void startTransport(); diff --git a/muse2/muse/driver/rtctimer.cpp b/muse2/muse/driver/rtctimer.cpp index e232b995..96585f87 100644 --- a/muse2/muse/driver/rtctimer.cpp +++ b/muse2/muse/driver/rtctimer.cpp @@ -1,12 +1,12 @@ - //========================================================= - // MusE - // Linux Music Editor - // $Id: rtctimer.cpp,v 1.1.2.11 2009/03/09 02:05:18 terminator356 Exp $ - // - // Most code moved from midiseq.cpp by Werner Schweer. - // - // (C) Copyright -2004 Werner Schweer (werner@seh.de) - // (C) Copyright 2004 Robert Jonsson (rj@spamatica.se) +//========================================================= +// MusE +// Linux Music Editor +// $Id: rtctimer.cpp,v 1.1.2.11 2009/03/09 02:05:18 terminator356 Exp $ +// +// Most code moved from midiseq.cpp by Werner Schweer. +// +// (C) Copyright -2004 Werner Schweer (werner@seh.de) +// (C) Copyright 2004 Robert Jonsson (rj@spamatica.se) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -22,7 +22,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // - //========================================================= +//========================================================= #include <linux/version.h> #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) |