Click here to Skip to main content
15,893,904 members
Articles / Artificial Intelligence

Developing MIDI applications with DirectMusic

Rate me:
Please Sign up or sign in to vote.
4.91/5 (45 votes)
11 Apr 2008LGPL325 min read 613K   9.5K   147  
A wrapper class library for the DirectMusic MIDI.
/*
Module : KeybDlg.h
Purpose: Defines the header implementation for the CKeybDlg class
Created: CJP / 10-4-2002
History: CJP / 21-7-2002 
	
	  1. Solved problems with Midi port selection
	  
	  2. Improved built-in keyboard
		
	  3. Supervised the multithread-safe application	

	  4. Improved the interactive interface 
	  
	
Copyright (c) 2002 by C. Jim�nez de Parga  
All rights reserved.
*/

// Some required headers

#include <afxmt.h>
#include "CMidiPort.h"

#if !defined(AFX_KEYBDLG_H__3BE1DA07_610B_11D6_B3BC_EC5E2C31CF36__INCLUDED_)
#define AFX_KEYBDLG_H__3BE1DA07_610B_11D6_B3BC_EC5E2C31CF36__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define MAX_INPORTS 10		// Space to store the maximum midi ports
#define MAX_OUTPORTS 30
#define MAX_LIST_ITEMS 1000	// Maximum list items 


/////////////////////////////////////////////////////////////////////////////
// CKeybDlg dialog

class CKeybDlg : public CDialog
{
// Construction
public:
	CString GetEspValue(unsigned char note);
	CKeybDlg(CWnd* pParent = NULL);	// standard constructor
	void EnumPorts();
	BOOL InitializeLibrary();
	void InitializeDirectMusic();
	void InitializeKeyboard();
	void InitializeInstruments();
	void InitializeMessageList();
	void InitializeControls();
	BOOL AddListCtrl(unsigned char note,unsigned char velocity);
	void StoresInformation(LVITEM &lvi,int nSubItem,CString strCad);
	void CloseDown();

	void RecvNote(unsigned char note);
	void ReleaseNote(unsigned char note);
	void SendMidiMsg(unsigned char note,BOOL bOn);
	CString GetEngValue(unsigned char note);
	DWORD CodeMidiMsg(unsigned char note,unsigned char velocity,BOOL bOn);
	void DecodeMidiMsg(DWORD dwMsg,unsigned char *note,unsigned char *velocity,BOOL *bOn);
	void StopRecord();
	void ReleaseAllKeys();
	DWORD AllnotesOff();
	
	BOOL m_bAbandon,m_bRec,m_bExitPlayBack;
	int nInPortSel,nOutPortSel;
	UCHAR nLoNote,nHiNote;
	// Dialog Data
	//{{AFX_DATA(CKeybDlg)
	enum { IDD = IDD_KEYB_DIALOG };
	CStatic	m_Image;
	CComboBox	m_NoteRange;
	CProgressCtrl	m_MemProgress;
	CButton	m_Stop;
	CButton	m_Rec;
	CButton	m_Play;
	CComboBox	m_OutPortList;
	CComboBox	m_InPortList;
	CListCtrl	m_MessagesList;
	CComboBox	m_InstList;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CKeybDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;
	INFOPORT InfInPort[MAX_INPORTS];		// Declaration of port info arrays	
	INFOPORT InfOutPort[MAX_OUTPORTS];
	// Generated message map functions
	//{{AFX_MSG(CKeybDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnButtonExpand();
	afx_msg void OnSelchangeInstruments();
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnRec();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnPlay();
	afx_msg void OnStop();
	afx_msg void OnClose();
	afx_msg void OnClear();
	afx_msg void OnSelchangeOutputPorts();
	afx_msg void OnSelchangeInputPorts();
	afx_msg void OnSelchangeNoteRange();
	afx_msg void OnHelp();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_KEYBDLG_H__3BE1DA07_610B_11D6_B3BC_EC5E2C31CF36__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
Spain Spain
I obtained my PhD degree in Computer Graphics at the National Distance Education University (UNED) in October 2019. I also hold a Ms. degree in Software Engineering and Computer Systems and a Bs. degree in Computer Science from the National Distance Education University (UNED).
I have been employed as a C++ software developer in several companies since year 2000.
I currently work as a Tutor-Professor of Symbolic Logic, Discrete Math and Java Object-Oriented Programming at UNED-Cartagena (Spain) since 2015.

Comments and Discussions