/[svn]/linuxsampler/trunk/src/midiin.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/midiin.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 18 by schoenebeck, Sun Dec 7 05:03:43 2003 UTC revision 23 by schoenebeck, Thu Dec 25 18:03:43 2003 UTC
# Line 23  Line 23 
23  #include "midiin.h"  #include "midiin.h"
24    
25  MidiIn::MidiIn(AudioThread* pAudioThread) : Thread(true, 1, -1) {  MidiIn::MidiIn(AudioThread* pAudioThread) : Thread(true, 1, -1) {
26        this->seq_handle   = NULL;
27      this->pAudioThread = pAudioThread;      this->pAudioThread = pAudioThread;
28      memset(MIDIControllerTable, 0x00, 128); // set all controller values to zero      memset(MIDIControllerTable, 0x00, 128); // set all controller values to zero
29  }  }
# Line 32  MidiIn::~MidiIn() { Line 33  MidiIn::~MidiIn() {
33  }  }
34    
35  int MidiIn::open_alsa_midi_seq(void) {  int MidiIn::open_alsa_midi_seq(void) {
     int portid;  
36      if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) {      if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) {
37          fprintf(stderr, "Error opening ALSA sequencer.\n");          fprintf(stderr, "Error opening ALSA sequencer.\n");
38          exit(1);          exit(1);
39      }      }
40        this->AlsaID = snd_seq_client_id(seq_handle);
41      snd_seq_set_client_name(seq_handle, "LinuxSampler");      snd_seq_set_client_name(seq_handle, "LinuxSampler");
42      if ((portid = snd_seq_create_simple_port(seq_handle, "LinuxSampler",      if ((this->AlsaPort = snd_seq_create_simple_port(seq_handle, "LinuxSampler",
43                                               SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,                                                       SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
44                                               SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {                                                       SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
45          fprintf(stderr, "Error creating sequencer port.\n");          fprintf(stderr, "Error creating sequencer port.\n");
46          exit(1);          exit(1);
47      }      }
# Line 50  int MidiIn::open_alsa_midi_seq(void) { Line 51  int MidiIn::open_alsa_midi_seq(void) {
51  void MidiIn::close_alsa_midi_seq(void) {  void MidiIn::close_alsa_midi_seq(void) {
52  }  }
53    
54    /**
55     * Makes a connection to another Alsa sequencer client, so that all MIDI
56     * events from e.g. a keyboard are always delivered to us.
57     *
58     * @param Client - Alsa sequencer client ID and port string to connect to
59     *                (e.g. "64:0")
60     */
61    void MidiIn::SubscribeToClient(const char* Client) {
62        if (!this->seq_handle) {  // if we haven't registered our seq client yet
63            int res = open_alsa_midi_seq();
64            if (res < 0) {
65                fprintf(stderr,"Opening of MIDI in device failed, exiting.\n");
66                exit(EXIT_FAILURE);
67            }
68        }
69    
70        snd_seq_addr_t sender, dest;
71        snd_seq_port_subscribe_t* subs;
72        int extClientID, extPortID;
73    
74        sscanf(Client, "%d:%d", &extClientID, &extPortID);
75        sender.client = (char) extClientID;
76        sender.port   = (char) extPortID;
77        dest.client   = (char) this->AlsaID;
78        dest.port     = (char) this->AlsaPort;
79        snd_seq_port_subscribe_alloca(&subs);
80        snd_seq_port_subscribe_set_sender(subs, &sender);
81        snd_seq_port_subscribe_set_dest(subs, &dest);
82        snd_seq_port_subscribe_set_queue(subs, 1);
83        snd_seq_port_subscribe_set_time_update(subs, 1);
84        snd_seq_port_subscribe_set_time_real(subs, 1);
85        if (snd_seq_subscribe_port(this->seq_handle, subs) < 0) {
86            fprintf(stderr, "Unable to subscribe to client \'%s\' (%s)\n", Client, snd_strerror(errno));
87        }
88    }
89    
90  int MidiIn::Main() {  int MidiIn::Main() {
91      int res = open_alsa_midi_seq();      if (!this->seq_handle) {  // if we haven't registered our seq client yet
92      if (res < 0) {          int res = open_alsa_midi_seq();
93          fprintf(stderr,"opening of MIDI in device failed, exiting.\n");          if (res < 0) {
94          exit(1);              fprintf(stderr,"Opening of MIDI in device failed, exiting.\n");
95                exit(EXIT_FAILURE);
96            }
97      }      }
98    
99      int npfd;      int npfd;

Legend:
Removed from v.18  
changed lines
  Added in v.23

  ViewVC Help
Powered by ViewVC