Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Wrapper Library for Windows MIDI API

, 28 Jan 2008
A small library encapsulating the Windows MIDI API
mididevdemo.zip
MIDIDeviceDemo.exe
mididevdemo_v2.zip
MIDIDevDemo v2
MIDIDevDemo v2.clw
MIDIDevDemo v2.dsp
MIDIDevDemo v2.dsw
MIDIDevDemo v2.ncb
MIDIDevDemo v2.opt
MIDIDevDemo v2.plg
res
MIDIDevDemo v2.ico
midiwrapper.zip
MIDIDeviceDemo.zip
MIDIWrapperSrc.zip
midiwrappersource.zip
MIDIWrapper Source
midiwrapper_demo.zip
MIDIDevDemo v2.clw
MIDIDevDemo v2.dsp
MIDIDevDemo v2.dsw
MIDIDevDemo v2.ico
midiwrapper_source.zip
MIDIWrapper_Source
MIDIWrapper Source
midiwrapper_src.zip
/*

  CLongMsg.cpp

  Implementation for the CLongMsg class.

  Copyright (C) 2002 Leslie Sanford

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
  USA

  Contact: Leslie Sanford (jabberdabber@hotmail.com)

  Last modified: 12/14/2002

*/


//---------------------------------------------------------------------
// Dependencies
//---------------------------------------------------------------------


#include "StdAfx.h"
#include "LongMsg.h"
#include "MIDIOutDevice.h"


// Using declaration
using midi::CLongMsg;


//---------------------------------------------------------------------
// CLongMsg implementation
//---------------------------------------------------------------------


// Default constructor
CLongMsg::CLongMsg() :
m_Msg(0),
m_Length(0)
{}


// Constructor
CLongMsg::CLongMsg(const char *Msg, DWORD Length) :
m_Msg(0),
m_Length(0)
{
    SetMsg(Msg, Length);
}


// Constructor
CLongMsg::CLongMsg(const CLongMsg &Msg)
{
    m_Msg = 0;
    m_Length = 0;

    *this = Msg;
}


// Destructor
CLongMsg::~CLongMsg()
{
    // Release resources for this object if they exist
    if(m_Msg != 0)
    {
        delete [] m_Msg;
    }
}


// Assignment
CLongMsg &CLongMsg::operator = (const CLongMsg &Msg)
{
    // Test for self assignment
    if(this != &Msg)
    {
        SetMsg(Msg.m_Msg, Msg.m_Length);
    }

    return *this;
}


// Sends MIDI message
void CLongMsg::SendMsg(midi::CMIDIOutDevice &OutDevice)
{
    OutDevice.SendMsg(m_Msg, m_Length);
}


// Sets message
void CLongMsg::SetMsg(const char *Msg, DWORD Length)
{
    // Release old message if it exists
    if(m_Msg != 0)
    {
        delete [] m_Msg;
    }

    // 
    // Allocate and initialize new message
    //

    m_Msg = new char[Length];
    m_Length = Length;

    for(DWORD i = 0; i < m_Length; i++)
    {
        m_Msg[i] = Msg[i];
    }
}


// Subscripting
char &CLongMsg::operator [] (int i)
{
    // Bounds checking
    if(m_Length == 0 || i < 0 || i >= m_Length)
    {
        throw CLongMsgIndexOutOfBounds();
    }

    return m_Msg[i];
}

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 MIT License

Share

About the Author

Leslie Sanford

United States United States
Aside from dabbling in BASIC on his old Atari 1040ST years ago, Leslie's programming experience didn't really begin until he discovered the Internet in the late 90s. There he found a treasure trove of information about two of his favorite interests: MIDI and sound synthesis.
 
After spending a good deal of time calculating formulas he found on the Internet for creating new sounds by hand, he decided that an easier way would be to program the computer to do the work for him. This led him to learn C. He discovered that beyond using programming as a tool for synthesizing sound, he loved programming in and of itself.
 
Eventually he taught himself C++ and C#, and along the way he immersed himself in the ideas of object oriented programming. Like many of us, he gotten bitten by the design patterns bug and a copy of GOF is never far from his hands.
 
Now his primary interest is in creating a complete MIDI toolkit using the C# language. He hopes to create something that will become an indispensable tool for those wanting to write MIDI applications for the .NET framework.
 
Besides programming, his other interests are photography and playing his Les Paul guitars.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 28 Jan 2008
Article Copyright 2002 by Leslie Sanford
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid