~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to midiport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//=========================================================
2
2
//  MusE
3
3
//  Linux Music Editor
4
 
//  $Id: midiport.cpp,v 1.6 2002/02/27 09:52:46 muse Exp $
 
4
//  $Id: midiport.cpp,v 1.3 2003/11/30 21:36:38 wschweer Exp $
5
5
//
6
6
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
7
7
//=========================================================
16
16
#include "xml.h"
17
17
#include "globals.h"
18
18
#include "midithread.h"
19
 
#include "event.h"
 
19
#include "mpevent.h"
20
20
 
21
21
MidiPort midiPorts[MIDI_PORTS];
22
22
 
42
42
      _masterVol  = 16383;
43
43
      _device     = 0;
44
44
      _instrument = 0;
 
45
      _rwFlags    = 3;  // read + write
45
46
      for (int i = 0; i < MIDI_CHANNELS; ++i)
46
47
            resetIstate(i, false);
47
48
      }
201
202
      static unsigned char data2[] = { 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x33, 0x50, 0x3c };
202
203
      static unsigned char data3[] = { 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x34, 0x50, 0x3b };
203
204
 
204
 
      sysex(gsOnMsg, gsOnMsgLen);
205
 
      usleep(10000);   // wait 10ms
206
 
      sysex(data2, sizeof(data2));
207
 
      usleep(10000);   // wait 10ms
208
 
      sysex(data3, sizeof(data3));
 
205
      if (_device) {
 
206
            sysex(gsOnMsg, gsOnMsgLen);
 
207
            usleep(10000);   // wait 10ms
 
208
            sysex(data2, sizeof(data2));
 
209
            usleep(10000);   // wait 10ms
 
210
            sysex(data3, sizeof(data3));
 
211
            }
209
212
 
210
213
      for (int i = 0; i < MIDI_CHANNELS; ++i) {
211
214
            resetCstate(i, false);
225
228
void MidiPort::xgOn()
226
229
      {
227
230
      gmOn();
228
 
      usleep(200000);   // wait 200ms
229
 
      sysex(xgOnMsg, xgOnMsgLen);
 
231
      if (_device) {
 
232
            usleep(200000);   // wait 200ms
 
233
            sysex(xgOnMsg, xgOnMsgLen);
 
234
            }
230
235
      for (int i = 0; i < MIDI_CHANNELS; ++i) {
231
 
            _cState[i].controller[0] = 0;
232
 
            _cState[i].controller[1] = 0;
233
 
            _cState[i].controller[5] = 0;
234
 
            _cState[i].controller[7] = 0x64;
 
236
            _cState[i].controller[0]  = 0;
 
237
            _cState[i].controller[1]  = 0;
 
238
            _cState[i].controller[5]  = 0;
 
239
            _cState[i].controller[7]  = 0x64;
235
240
            _cState[i].controller[10] = 0x40;
236
241
            _cState[i].controller[11] = 0x7f;
237
242
            _cState[i].controller[32] = 0;
269
274
            setCtrl(chn, CTRL_HBANK, hbank);
270
275
      if (lbank != -1)
271
276
            setCtrl(chn, CTRL_LBANK, lbank);
272
 
      programChange(chn, prg);
 
277
      if (prg != -1)
 
278
            programChange(chn, prg);
273
279
      }
274
280
 
275
281
//---------------------------------------------------------
281
287
      if (_cState[chn].program != prg) {
282
288
            _cState[chn].program = prg;
283
289
            if (_device) {
284
 
                  MidiEvent event(portno(), chn, 0, MidiEvent::Program,
285
 
                     prg, 0, 0, 0);
 
290
                  MidiPlayEvent event(0, chn, 0xc0, prg, 0);
286
291
                  _device->putEvent(&event);
287
292
                  }
288
293
            }
292
297
//   bender
293
298
//---------------------------------------------------------
294
299
 
295
 
void MidiPort::bender(int chn, int val)
 
300
void MidiPort::bender(int chn, int a)
296
301
      {
297
 
      if (val != _cState[chn].pitch) {
298
 
            _cState[chn].pitch = val;
 
302
      if (a != _cState[chn].pitch) {
 
303
            _cState[chn].pitch = a;
299
304
            if (_device) {
300
 
                  MidiEvent event(portno(), chn, 0, MidiEvent::Pitch,
301
 
                     val, 0, 0, 0);
 
305
                  a += 8192;
 
306
                  int b = a >> 7;
 
307
                  MidiPlayEvent event(0, chn, 0xe0, a & 0x7f, b & 0x7f);
302
308
                  _device->putEvent(&event);
303
309
                  }
304
310
            }
311
317
void MidiPort::sysex(const unsigned char* p, int n)
312
318
      {
313
319
      if (_device) {
314
 
            MidiEvent event(portno(), 0, 0, MidiEvent::Sysex, n, p);
 
320
            MidiPlayEvent event(0, p, n);
315
321
            _device->putEvent(&event);
316
322
            }
317
323
      }
362
368
 
363
369
void MidiPort::setMasterVol(int val)
364
370
      {
 
371
      if (!_device)
 
372
            return;
365
373
      _masterVol = val;
366
374
      unsigned char data[6] = { 0x7f, 0x7f, 0x04, 0x01, 0x00, 0x00 };
367
375
      data[4] = val & 0x7f;
428
436
 
429
437
void MidiPort::setCtrl(int chn, int ctrl, int val)
430
438
      {
431
 
      if (_cState[chn].controller[ctrl] != val) {
432
 
            _cState[chn].controller[ctrl] = val;
433
 
            if (_device) {
434
 
                  MidiEvent event(portno(), chn, 0, MidiEvent::Ctrl7,
435
 
                     ctrl, val, 0, 0);
436
 
                  _device->putEvent(&event);
437
 
                  }
 
439
      if (_device) {
 
440
            MidiPlayEvent event(0, chn, 0xb0, ctrl, val & 0x7f);
 
441
            putEvent(&event);
438
442
            }
439
443
      }
440
444
 
442
446
//   putEvent
443
447
//---------------------------------------------------------
444
448
 
445
 
void MidiPort::putEvent(const MidiEvent* ev)
 
449
void MidiPort::putEvent(const MidiPlayEvent* ev)
446
450
      {
447
 
      if (!_device)
 
451
      if (!_device) {
 
452
//            printf("MidiPort: putEvent: no device for port %d\n", portno());
448
453
            return;
449
 
      int chn = ev->channel();
450
 
      int a = ev->dataA();
451
 
      int b = ev->dataB();
452
 
      switch(ev->type()) {
453
 
            case MidiEvent::Ctrl14:
454
 
                  if (_cState[chn].controller[a & 0x7f] == b & 0x7f) {
455
 
                        a >>= 7;
456
 
                        b >>= 7;
457
 
                        if (_cState[chn].controller[a] == b)
458
 
                              return;
459
 
                        MidiEvent e(0, chn, 0, MidiEvent::Ctrl7, a, b, 0, 0);
460
 
                        _device->putEvent(&e);
461
 
                        _cState[chn].controller[a] = b;
462
 
                        return;
463
 
                        }
464
 
                  break;
465
 
            case MidiEvent::Ctrl7:
466
 
                  if (_cState[chn].controller[a] == b)
467
 
                        return;
468
 
                  _cState[chn].controller[a] = b;
469
 
                  break;
470
 
            default:
471
 
                  // TODO
472
 
                  break;
 
454
            }
 
455
      if (ev->type() == 0xb0) {     // ctrl event
 
456
            int chn = ev->channel();
 
457
            int a   = ev->dataA();
 
458
            int b   = ev->dataB();
 
459
//            if ((a == CTRL_LDATA || a == CTRL_LNRPN || a == CTRL_HNRPN
 
460
//               || a == CTRL_LRPN || a == CTRL_HRPN)
 
461
//               && (_cState[chn].controller[a] == b)) {
 
462
//                  printf("optimize ctrl event %d val %d\n", a, b);
 
463
//TODO                  return;
 
464
//                  }
 
465
            _cState[chn].controller[a] = b;
473
466
            }
474
467
      _device->putEvent(ev);
475
468
      }