File: MIDIOut_example.cxx

package info (click to toggle)
clam 1.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,836 kB
  • ctags: 20,981
  • sloc: cpp: 92,504; python: 9,721; ansic: 1,602; xml: 444; sh: 239; makefile: 153; perl: 54; asm: 15
file content (100 lines) | stat: -rw-r--r-- 2,450 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
 *                         UNIVERSITAT POMPEU FABRA
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "MIDIManager.hxx"
#include "MIDIIOConfig.hxx"
#include "MIDIOutControl.hxx"

#ifdef WIN32
	#include "windows.h"
#endif

using namespace CLAM;

void CrossPlatformSleep(int seconds)
{
	#ifdef WIN32
		Sleep(1000*seconds);
	#else 
		sleep(seconds);
	#endif
}

int main()
{
	MIDIManager manager;
	MIDIIOConfig outNoteCfg;

	// NOTE OUT EXAMPLE WITH FIXED CHANNEL`
	outNoteCfg.SetDevice("alsa:hw:1,0");
	outNoteCfg.SetChannel(1);

	outNoteCfg.SetMessage(MIDI::eNoteOn);

	MIDIOutControl outNote(outNoteCfg);
	
	manager.Start();
	
	SendFloatToInControl(outNote,0,60);
	SendFloatToInControl(outNote,1,120);

	CrossPlatformSleep(1);
	SendFloatToInControl(outNote,0,60);
	SendFloatToInControl(outNote,1,0);
	
	CrossPlatformSleep(1);

	// STOP HERE
	return 0;
	// NOTE OUT EXAMPLE WITH VARIABLE CHANNEL
	MIDIIOConfig outNote2Cfg;

	outNote2Cfg.SetDevice("default:default");
	outNote2Cfg.SetChannel(0); // means: create an in control!

	outNote2Cfg.SetMessage(MIDI::eNoteOn);

	MIDIOutControl outNote2(outNote2Cfg);
	
	SendFloatToInControl(outNote2,0,3);
	SendFloatToInControl(outNote2,1,60);
	SendFloatToInControl(outNote2,2,120);

	SendFloatToInControl(outNote2,0,3);
	SendFloatToInControl(outNote2,1,60);
	SendFloatToInControl(outNote2,2,120);

	// VOLUME CONTROL CHANGE EXAMPLE
	MIDIIOConfig volCtrlCfg;

	volCtrlCfg.SetDevice("default:default");
	volCtrlCfg.SetChannel(1);
	volCtrlCfg.SetFirstData(7); // 7 == volume ctrl change
	

	volCtrlCfg.SetMessage(MIDI::eControlChange);

	MIDIOutControl volCtrl(volCtrlCfg);

	// send value 110 to volume control change on channel 1
	SendFloatToInControl(volCtrl,0,110);
}