File: midiguicomponent.cpp

package info (click to toggle)
ams 1.8.7-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,880 kB
  • ctags: 2,171
  • sloc: cpp: 17,793; makefile: 433; sh: 101
file content (128 lines) | stat: -rw-r--r-- 4,096 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <qhbox.h>
#include <qvbox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qpopupmenu.h>
#include <stdio.h>
#include "synthdata.h"
#include "midicontroller.h"
#include "midicontrollerlist.h"
#include "midiguicomponent.h"
#include "midiwidget.h"

MidiGUIcomponent::MidiGUIcomponent(QObject *p_parentModule, SynthData *p_synthdata, QWidget * parent, const char * name)
           : QHBox(parent, name) {

  parentModule = p_parentModule;
  synthdata = p_synthdata;
  controllerOK = false;
  midiSign = 1;
  listViewItem = NULL;
  midiGUIcomponentListIndex = 0;
  QObject::connect(this, SIGNAL(guiComponentTouched()),
                   (MidiWidget *)synthdata->midiWidget, SLOT(updateGuiComponent())); 
}

MidiGUIcomponent::~MidiGUIcomponent() {
}

void MidiGUIcomponent::connectToController(MidiController *p_midiController) {

  if (!midiControllerList.contains(p_midiController)) {
    QObject::connect(p_midiController, SIGNAL(midiValueChanged(int)),
                     this, SLOT(midiValueChanged(int)));  
    midiControllerList.append(p_midiController);
    ((MidiWidget *)synthdata->midiWidget)->addMidiGuiComponent(p_midiController, (QObject *)this);
    controllerOK = false;
  }
}
   
void MidiGUIcomponent::disconnectController(MidiController *p_midiController) {

  QObject::disconnect(p_midiController, SIGNAL(midiValueChanged(int)),
                      this, SLOT(midiValueChanged(int)));
  midiControllerList.remove(p_midiController);
}  

void MidiGUIcomponent::connectToController() {

  MidiController *midiController;
  
  if ((midiController = ((MidiWidget *)synthdata->midiWidget)->getSelectedController())) {
    if (!midiControllerList.contains(midiController)) {
      QObject::connect(midiController, SIGNAL(midiValueChanged(int)),
                       this, SLOT(midiValueChanged(int)));
      midiControllerList.append(midiController);
      ((MidiWidget *)synthdata->midiWidget)->addMidiGuiComponent(midiController, (QObject *)this);
      controllerOK = false;
    }
  }
} 

void MidiGUIcomponent::disconnectController() {
   
  if (((MidiWidget *)synthdata->midiWidget)->getSelectedController()) {
    QObject::disconnect(((MidiWidget *)synthdata->midiWidget)->getSelectedController(), SIGNAL(midiValueChanged(int)),
                       this, SLOT(midiValueChanged(int)));
    midiControllerList.remove(((MidiWidget *)synthdata->midiWidget)->getSelectedController());
  }
}

void MidiGUIcomponent::disconnectController(int index) {

  if (midiControllerList.count()) {
    QObject::disconnect(midiControllerList.at(index), SIGNAL(midiValueChanged(int)),
                       this, SLOT(midiValueChanged(int)));
    ((MidiWidget *)synthdata->midiWidget)->deleteMidiGuiComponent(midiControllerList.at(index), (QObject *)this);
    midiControllerList.remove(midiControllerList.at(index));
  }
}

void MidiGUIcomponent::setMidiValue(int value) {

}

int MidiGUIcomponent::getMidiValue() {

  return(0);
}

void MidiGUIcomponent::midiValueChanged(int value) {

  int type, ch, param;
  snd_seq_event_t ev;

  if (!controllerOK) {
    if ((synthdata->midiControllerMode == 1) && midiControllerList.count()) {
      type = midiControllerList.at(0)->type;
      if (type == SND_SEQ_EVENT_CONTROLLER) {
        ch = midiControllerList.at(0)->ch;
        param = midiControllerList.at(0)->param;
        snd_seq_ev_clear(&ev);
        snd_seq_ev_set_subs(&ev);
        snd_seq_ev_set_direct(&ev);
        ev.type = SND_SEQ_EVENT_CONTROLLER;
        ev.data.control.channel = ch;
        ev.data.control.param = param;
        ev.data.control.value = getMidiValue();
        snd_seq_ev_set_source(&ev, synthdata->midi_out_port[0]);
        snd_seq_event_output_direct(synthdata->seq_handle, &ev);
//        fprintf(stderr, "--> %d %d %d\n", type, ch, param);
      }
      if (synthdata->midiControllerMode > 0) {
        controllerOK = true;
      }  
    }  
  }  
  setMidiValue(value);
}

void MidiGUIcomponent::resetControllerOK() {

  controllerOK = false;
}

void MidiGUIcomponent::invalidateController() {

  emit sigResetController();
}