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

« back to all changes in this revision

Viewing changes to muse/driver/alsamidi.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:
17
17
#include "../audio.h"
18
18
#include "mpevent.h"
19
19
//#include "sync.h"
 
20
#include "utils.h"
 
21
#include "audiodev.h"
 
22
#include "xml.h"
20
23
 
21
24
static int alsaSeqFdi = -1;
22
25
static int alsaSeqFdo = -1;
168
171
}
169
172
 
170
173
//---------------------------------------------------------
 
174
//   writeRouting
 
175
//---------------------------------------------------------
 
176
 
 
177
void MidiAlsaDevice::writeRouting(int level, Xml& xml) const
 
178
{
 
179
      // p3.3.45
 
180
      // If this device is not actually in use by the song, do not write any routes.
 
181
      // This prevents bogus routes from being saved and propagated in the med file.
 
182
      if(midiPort() == -1)
 
183
        return;
 
184
     
 
185
      QString s;
 
186
      /*
 
187
      //if(rwFlags() & 2)  // Readable
 
188
      {
 
189
        //RouteList* rl = _inRoutes;
 
190
        //for (ciRoute r = rl->begin(); r != rl->end(); ++r) 
 
191
        for (ciRoute r = _inRoutes.begin(); r != _inRoutes.end(); ++r) 
 
192
        {
 
193
          // Since an ALSA midi device supports read + write, this is the only way we can tell if this route is using the device as input.  
 
194
          if(r->type == Route::TRACK_ROUTE)
 
195
            continue;
 
196
            
 
197
          if(!r->name().isEmpty())
 
198
          {
 
199
            xml.tag(level++, "Route");
 
200
            
 
201
            //xml.strTag(level, "srcNode", r->name());
 
202
            xml.tag(level, "source type=\"%d\" name=\"%s\"/", r->type, r->name().latin1());
 
203
            
 
204
            //xml.strTag(level, "dstNode", name());
 
205
            xml.tag(level, "dest type=\"%d\" name=\"%s\"/", Route::ALSA_MIDI_ROUTE, name().latin1());
 
206
            
 
207
            xml.etag(level--, "Route");
 
208
          }
 
209
        }  
 
210
      } 
 
211
      */
 
212
      
 
213
      for (ciRoute r = _outRoutes.begin(); r != _outRoutes.end(); ++r) 
 
214
      {
 
215
        //if(r->type != Route::TRACK_ROUTE)
 
216
        //{  
 
217
        //  printf("MidiAlsaDevice::writeRouting Warning out route is not TRACK_ROUTE type\n");
 
218
        //  continue;
 
219
        //}
 
220
          
 
221
        if(!r->name().isEmpty())
 
222
        {
 
223
          //xml.tag(level++, "Route");
 
224
          
 
225
          s = QT_TR_NOOP("Route");
 
226
          if(r->channel != -1)
 
227
            s += QString(QT_TR_NOOP(" channel=\"%1\"")).arg(r->channel);
 
228
          xml.tag(level++, s);
 
229
          
 
230
          /*
 
231
          //xml.strTag(level, "srcNode", name());
 
232
          if(r->channel != -1)  
 
233
            //xml.tag(level, "source type=\"%d\" channel=\"%d\" name=\"%s\"/", Route::ALSA_MIDI_ROUTE, r->channel, name().latin1());
 
234
            //xml.tag(level, "source type=\"%d\" channel=\"%d\" name=\"%s\"/", Route::MIDI_DEVICE_ROUTE, r->channel, name().latin1());
 
235
            xml.tag(level, "source devtype=\"%d\" channel=\"%d\" name=\"%s\"/", MidiDevice::ALSA_MIDI, r->channel, name().latin1());
 
236
          else  
 
237
            //xml.tag(level, "source type=\"%d\" name=\"%s\"/", Route::ALSA_MIDI_ROUTE, name().latin1());
 
238
            //xml.tag(level, "source type=\"%d\" name=\"%s\"/", Route::MIDI_DEVICE_ROUTE, name().latin1());
 
239
          */  
 
240
            //xml.tag(level, "source devtype=\"%d\" name=\"%s\"/", MidiDevice::ALSA_MIDI, name().latin1());
 
241
            xml.tag(level, "source devtype=\"%d\" name=\"%s\"/", MidiDevice::ALSA_MIDI, Xml::xmlString(name()).latin1());
 
242
          
 
243
          /*
 
244
          //xml.strTag(level, "dstNode", r->name());
 
245
          if(r->channel != -1)  
 
246
          {
 
247
            if(r->type == Route::MIDI_DEVICE_ROUTE)  
 
248
              xml.tag(level, "dest devtype=\"%d\" channel=\"%d\" name=\"%s\"/", r->device->deviceType(), r->channel, r->name().latin1());
 
249
            else  
 
250
              xml.tag(level, "dest type=\"%d\" channel=\"%d\" name=\"%s\"/", r->type, r->channel, r->name().latin1());
 
251
          }
 
252
          else  
 
253
          {
 
254
            if(r->type == Route::MIDI_DEVICE_ROUTE)  
 
255
              xml.tag(level, "dest devtype=\"%d\" name=\"%s\"/", r->device->deviceType(), r->name().latin1());
 
256
            else  
 
257
              xml.tag(level, "dest type=\"%d\" name=\"%s\"/", r->type, r->name().latin1());
 
258
          }
 
259
          */
 
260
          
 
261
          s = QT_TR_NOOP("dest");
 
262
          if(r->type == Route::MIDI_DEVICE_ROUTE)
 
263
            s += QString(QT_TR_NOOP(" devtype=\"%1\"")).arg(r->device->deviceType());
 
264
          else
 
265
          if(r->type != Route::TRACK_ROUTE)
 
266
            s += QString(QT_TR_NOOP(" type=\"%1\"")).arg(r->type);
 
267
          //s += QString(QT_TR_NOOP(" name=\"%1\"/")).arg(r->name());
 
268
          s += QString(QT_TR_NOOP(" name=\"%1\"/")).arg(Xml::xmlString(r->name()));
 
269
          xml.tag(level, s);
 
270
          
 
271
          xml.etag(level--, "Route");
 
272
        }
 
273
      }
 
274
}
 
275
    
 
276
//---------------------------------------------------------
171
277
//   putEvent
172
278
//---------------------------------------------------------
173
279
 
205
311
                  int a   = e.dataA();
206
312
                  int b   = e.dataB();
207
313
                  int chn = e.channel();
208
 
                  if (a < 0x1000) {          // 7 Bit Controller
 
314
                  // p3.3.37
 
315
                  //if (a < 0x1000) {          // 7 Bit Controller
 
316
                  if (a < CTRL_14_OFFSET) {          // 7 Bit Controller
209
317
                        snd_seq_ev_set_controller(&event, chn, a, b);
210
318
                        }
211
 
                  else if (a < 0x20000) {     // 14 bit high resolution controller
 
319
                  //else if (a < 0x20000) {     // 14 bit high resolution controller
 
320
                  else if (a < CTRL_RPN_OFFSET) {     // 14 bit high resolution controller
212
321
                        int ctrlH = (a >> 8) & 0x7f;
213
322
                        int ctrlL = a & 0x7f;
214
323
                        a = (ctrlH << 7) + ctrlL;
215
324
                        snd_seq_ev_set_controller(&event, chn, a, b);
216
325
                        event.type = SND_SEQ_EVENT_CONTROL14;
217
326
                        }
218
 
                  else if (a < 0x30000) {     // RPN 7-Bit Controller
 
327
                  //else if (a < 0x30000) {     // RPN 7-Bit Controller
 
328
                  else if (a < CTRL_NRPN_OFFSET) {     // RPN 7-Bit Controller
219
329
                        int ctrlH = (a >> 8) & 0x7f;
220
330
                        int ctrlL = a & 0x7f;
221
331
                        a = (ctrlH << 7) + ctrlL;
223
333
                        snd_seq_ev_set_controller(&event, chn, a, b);
224
334
                        event.type = SND_SEQ_EVENT_REGPARAM;
225
335
                        }
226
 
                  else if (a < 0x40000) {     // NRPN 7-Bit Controller
 
336
                  //else if (a < 0x40000) {     // NRPN 7-Bit Controller
 
337
                  else if (a < CTRL_INTERNAL_OFFSET) {     // NRPN 7-Bit Controller
227
338
                        int ctrlH = (a >> 8) & 0x7f;
228
339
                        int ctrlL = a & 0x7f;
229
340
                        a = (ctrlH << 7) + ctrlL;
231
342
                        snd_seq_ev_set_controller(&event, chn, a, b);
232
343
                        event.type = SND_SEQ_EVENT_NONREGPARAM;
233
344
                        }
234
 
                  else if (a < 0x60000) {     // RPN14 Controller
 
345
                  //else if (a < 0x60000) {     // RPN14 Controller
 
346
                  else if (a < CTRL_NRPN14_OFFSET) {     // RPN14 Controller
235
347
                        int ctrlH = (a >> 8) & 0x7f;
236
348
                        int ctrlL = a & 0x7f;
237
349
                        a = (ctrlH << 7) + ctrlL;
238
350
                        snd_seq_ev_set_controller(&event, chn, a, b);
239
351
                        event.type = SND_SEQ_EVENT_REGPARAM;
240
352
                        }
241
 
                  else if (a < 0x70000) {     // NRPN14 Controller
 
353
                  //else if (a < 0x70000) {     // NRPN14 Controller
 
354
                  else if (a < CTRL_NONE_OFFSET) {     // NRPN14 Controller
242
355
                        int ctrlH = (a >> 8) & 0x7f;
243
356
                        int ctrlL = a & 0x7f;
244
357
                        a = (ctrlH << 7) + ctrlL;
410
523
                  
411
524
                  }
412
525
            }
413
 
      snd_seq_set_client_name(alsaSeq, "MusE Sequencer");
 
526
      
 
527
      // p3.3.38
 
528
      //snd_seq_set_client_name(alsaSeq, "MusE Sequencer");
 
529
      snd_seq_set_client_name(alsaSeq, audioDevice->clientName());
 
530
      
414
531
      int ci = snd_seq_poll_descriptors_count(alsaSeq, POLLIN);
415
532
      int co = snd_seq_poll_descriptors_count(alsaSeq, POLLOUT);
416
533
 
713
830
                        break;
714
831
 
715
832
                  case SND_SEQ_EVENT_CLOCK:
716
 
                        midiSeq->realtimeSystemInput(curPort, 0xf8);
 
833
                        midiSeq->realtimeSystemInput(curPort, ME_CLOCK);
717
834
                        //mdev->syncInfo().trigMCSyncDetect();
718
835
                        break;
719
836
 
720
837
                  case SND_SEQ_EVENT_START:
721
 
                        midiSeq->realtimeSystemInput(curPort, 0xfa);
 
838
                        midiSeq->realtimeSystemInput(curPort, ME_START);
722
839
                        break;
723
840
 
724
841
                  case SND_SEQ_EVENT_CONTINUE:
725
 
                        midiSeq->realtimeSystemInput(curPort, 0xfb);
 
842
                        midiSeq->realtimeSystemInput(curPort, ME_CONTINUE);
726
843
                        break;
727
844
 
728
845
                  case SND_SEQ_EVENT_STOP:
729
 
                        midiSeq->realtimeSystemInput(curPort, 0xfc);
 
846
                        midiSeq->realtimeSystemInput(curPort, ME_STOP);
730
847
                        break;
731
848
 
732
849
                  case SND_SEQ_EVENT_TICK:
733
 
                        midiSeq->realtimeSystemInput(curPort, 0xf9);
 
850
                        midiSeq->realtimeSystemInput(curPort, ME_TICK);
734
851
                        //mdev->syncInfo().trigTickDetect();
735
852
                        break;
736
853
 
737
854
                  case SND_SEQ_EVENT_SYSEX:
 
855
                        
 
856
                        // TODO: Deal with large sysex, which are broken up into chunks!
 
857
                        // For now, do not accept if the first byte is not SYSEX or the last byte is not EOX, 
 
858
                        //  meaning it's a chunk, possibly with more chunks to follow.
 
859
                        if((*((unsigned char*)ev->data.ext.ptr) != ME_SYSEX) ||
 
860
                           (*(((unsigned char*)ev->data.ext.ptr) + ev->data.ext.len - 1) != ME_SYSEX_END))
 
861
                        {
 
862
                          printf("MusE: alsaProcessMidiInput sysex chunks not supported!\n");
 
863
                          break;
 
864
                        }
 
865
                        
738
866
                        event.setTime(0);      // mark as used
739
867
                        event.setType(ME_SYSEX);
740
868
                        event.setData((unsigned char*)(ev->data.ext.ptr)+1,
775
903
            if(event.type())
776
904
            {
777
905
              mdev->recordEvent(event);
778
 
              if(ev->type != SND_SEQ_EVENT_SYSEX)
 
906
              // p3.3.26 1/23/10 Moved to MidiDevice now. Anticipating Jack midi support, so don't make it ALSA specific. Tim.
 
907
              //if(ev->type != SND_SEQ_EVENT_SYSEX)
779
908
                // Trigger general activity indicator detector. Sysex has no channel, don't trigger.
780
 
                midiPorts[curPort].syncInfo().trigActDetect(event.channel());
 
909
              //  midiPorts[curPort].syncInfo().trigActDetect(event.channel());
781
910
            }
782
911
                  
783
912
            snd_seq_free_event(ev);