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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (hide annotations) (download)
Sun Dec 7 05:03:43 2003 UTC (20 years, 5 months ago) by schoenebeck
File size: 4329 byte(s)
* src/audioio.cpp: added support for Alsa 1.0.0
* src/audiothread.cpp: fixed several bugs in sustain pedal handling
* src/diskthread.cpp: fixed several bugs which occured under extreme
  conditions (endless loop in audiothread, freezing the whole application,
  outage of available disk streams)
* src/voice.cpp: fixed cubic interpolation (disabled by default; you can
  enable it by setting USE_LINEAR_INTERPOLATION to 0 in src/voice.h)
* src/configure.in: added check for Alsa version

1 schoenebeck 9 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck *
6     * *
7     * This program is free software; you can redistribute it and/or modify *
8     * it under the terms of the GNU General Public License as published by *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #include "midiin.h"
24    
25     MidiIn::MidiIn(AudioThread* pAudioThread) : Thread(true, 1, -1) {
26     this->pAudioThread = pAudioThread;
27     memset(MIDIControllerTable, 0x00, 128); // set all controller values to zero
28     }
29    
30     MidiIn::~MidiIn() {
31     close_alsa_midi_seq();
32     }
33    
34     int MidiIn::open_alsa_midi_seq(void) {
35     int portid;
36     if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) {
37     fprintf(stderr, "Error opening ALSA sequencer.\n");
38     exit(1);
39     }
40     snd_seq_set_client_name(seq_handle, "LinuxSampler");
41     if ((portid = snd_seq_create_simple_port(seq_handle, "LinuxSampler",
42     SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
43     SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
44     fprintf(stderr, "Error creating sequencer port.\n");
45     exit(1);
46     }
47     return 0;
48     }
49    
50     void MidiIn::close_alsa_midi_seq(void) {
51     }
52    
53     int MidiIn::Main() {
54     int res = open_alsa_midi_seq();
55     if (res < 0) {
56     fprintf(stderr,"opening of MIDI in device failed, exiting.\n");
57     exit(1);
58     }
59    
60     int npfd;
61     struct pollfd *pfd;
62     snd_seq_event_t *ev;
63    
64     npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
65     pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
66     snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
67     while (true) {
68     if (poll(pfd, npfd, 100000) > 0) {
69     do {
70     snd_seq_event_input(seq_handle, &ev);
71     switch (ev->type) {
72     case SND_SEQ_EVENT_CONTROLLER:
73 schoenebeck 18 pAudioThread->SendControlChange(ev->data.control.channel, ev->data.control.param, ev->data.control.value);
74 schoenebeck 9 break;
75    
76     case SND_SEQ_EVENT_PITCHBEND:
77 senoner 10 // fprintf(stderr, "Pitchbender event on Channel %2d: %5d \n",
78     // ev->data.control.channel, ev->data.control.value);
79 schoenebeck 9 break;
80    
81     case SND_SEQ_EVENT_NOTEON:
82     if (ev->data.note.velocity != 0) {
83 schoenebeck 18 pAudioThread->SendNoteOn(ev->data.note.note, ev->data.note.velocity);
84 schoenebeck 9 }
85     else {
86 schoenebeck 18 pAudioThread->SendNoteOff(ev->data.note.note, 0);
87 schoenebeck 9 }
88     break;
89    
90     case SND_SEQ_EVENT_NOTEOFF:
91 schoenebeck 18 pAudioThread->SendNoteOff(ev->data.note.note, ev->data.note.velocity);
92 schoenebeck 9 break;
93     }
94     snd_seq_free_event(ev);
95     } while (snd_seq_event_input_pending(seq_handle, 0) > 0);
96 schoenebeck 18 }
97     }
98 schoenebeck 9 }
99 senoner 10

  ViewVC Help
Powered by ViewVC