|
/*
__ __ _ ____ _ _________ __ ______ _ ____ __ _
| \/ || || _ \| | ( /_ _// \/_ _/| |/ \| \| |
| |\/| || || |_| | | \ \ | | | <> | | | | || <> || |\ |
|_| |_||_||____/|_| /___)|_| |_||_| |_| |_|\____/|_| \_|
////////////////////////////////////////////////////////////////////////
This program 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 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
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
Copyright (c) 2002-2003 by Carlos Jim�nez de Parga
All rights reserved.
For any suggestion or failure report, please contact me by e-mail:
cjimenez@servitel.es
///////////////////////////////////////////////////////////////////////
Module : Record.cpp
Purpose: Code implementation for the CRecord class
Date Format: Day/Month/Year
Created: CJP / 10-04-2002
History: CJP / 29-12-2003
// 11-10-2002 Update
1. Solved problems with Midi port selection
2. Improved built-in keyboard
3. Supervised the multithread-safe application
4. Improved the interactive interface
5. Application restructured to the new CDirectMidi wrapper
6. Added the Microsoft Software Synthesizer
7. Added keyboard support
8. Fixed bugs in classes design
9. Improved playback thread using Events
10. Guide line on the list control
// 6 - 10 - 2003 Update
11. Added exception handling
12. Included the piano keyboard control
13. Enhanced implicit multitask synchronization system
14. Simplified the class hierarchy
15. Program structure grouped into new classes
16. Fixed bugs in calls to DirectMidi library
17. Program released under GNU (General Public License) terms
// 29 - 12- 2003 Update
18. Fixed running status bug
19. Fixed DLS port bug
20. Fixed message list bugs
21. Loading and saving of .MDS sequenced files
22. Unlimited recording
*/
#include "stdafx.h"
#include "Record.h"
#include "time.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CRecord::CRecord()
{
nTotal = NoteArray.max_size(); //Initializes the total memory counter
}
CRecord::~CRecord()
{
ClearArray();
}
// Stores the current message
void CRecord::StoreMidiMsg(DWORD dwMsg)
{
DWORD dwdiff;
Msg Message;
GetSystemTime(&Current); // Calculates the elapsed time
if (nIndex == 0)
Start = Current;
dwdiff = (Current.wMilliseconds+Current.wSecond*1000+Current.wMinute*60000+Current.wHour*3600000)-
(Start.wMilliseconds+Start.wSecond*1000+Start.wMinute*60000+Start.wHour*3600000);
if (Start.wHour>Current.wHour) // In case 0:0:0:0 hours UTC
dwdiff = 86400000+dwdiff;
Message.wTime = static_cast<WORD>(dwdiff); // Stores the time when the message was generated
Message.wMsg = static_cast<WORD>(dwMsg >> 8); // Stores the message
// /----------FIRST BYTE---------\ /----SECOND BYTE---\
// ___________________________________________________
//| | | |
//|note on/off| Note 0-127 | Velocity 0-127 |
//|___________|___________________|___________________|
//
(static_cast<BYTE>(dwMsg & ~0xF) == 0x90) ?
(Message.wMsg |= 0x8000) : (Message.wMsg &= 0x7FFF);
NoteArray.push_back(Message); // Pushes the message into the array
nMsgRecorded = ++nIndex; // Increments the message counter and stores the total recorded
Start = Current;
}
// Returns the index
DWORD CRecord::GetIndex()
{
return nIndex;
}
// Sets the number of items that will be stored
void CRecord::SetTotalRecorded(DWORD dwSize)
{
nMsgRecorded = dwSize;
}
// Returns the total recorded messages
DWORD CRecord::GetTotalRecorded()
{
return nMsgRecorded;
}
// Set index to 0, start counting
void CRecord::ResetIndex()
{
nIndex = 0;
}
// Advance index in one unit
void CRecord::StepIndex()
{
nIndex++;
}
// Gets the message in the array pointed by the index
DWORD CRecord::GetStoredMessage()
{
DWORD dwAux;
dwAux = NoteArray[nIndex].wMsg & 0x7FFF; // Decodes the message
dwAux<<= 8;
((NoteArray[nIndex].wMsg & 0x8000) ? (dwAux|= 0x90):
(dwAux|= 0x80));
return dwAux;
}
// Returns the space memory for recording
DWORD CRecord::GetTotalMsgMemory()
{
return nTotal;
}
// Returns the time of a stored message given the index
DWORD CRecord::GetTime(DWORD dwIndex)
{
return NoteArray[dwIndex].wTime;
}
// Obtains a pointer to the internal array
void* CRecord::GetArrayPointer()
{
return &*NoteArray.begin();
}
// Erases all data in the array
void CRecord::ClearArray()
{
NoteArray.clear();
}
// Allocates array space given a number of items
void CRecord::AllocateSpace(DWORD dwSize)
{
NoteArray.resize(dwSize);
}
|
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.
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.