|
From: <pst...@us...> - 2008-03-30 15:37:22
|
Revision: 374
http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=374&view=rev
Author: pstieber
Date: 2008-03-30 08:37:16 -0700 (Sun, 30 Mar 2008)
Log Message:
-----------
Added some code for reading and writing MIDI files in ASCII format for
debug purposes. This was ported from version 4.1.3 in branches.
Modified Paths:
--------------
trunk/jazz/src/Makefile.am
trunk/jazz/vc8/JazzPlusPlus-VC8.vcproj
Added Paths:
-----------
trunk/jazz/src/AsciiMidiFile.cpp
trunk/jazz/src/AsciiMidiFile.h
Added: trunk/jazz/src/AsciiMidiFile.cpp
===================================================================
--- trunk/jazz/src/AsciiMidiFile.cpp (rev 0)
+++ trunk/jazz/src/AsciiMidiFile.cpp 2008-03-30 15:37:16 UTC (rev 374)
@@ -0,0 +1,192 @@
+//*****************************************************************************
+// The JAZZ++ Midi Sequencer
+//
+// Copyright (C) 1994-2000 Andreas Voss and Per Sigmond, all rights reserved.
+// Modifications Copyright (C) 2008 Peter J. Stieber
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+//*****************************************************************************
+
+#include "WxWidgets.h"
+
+#include "AsciiMidiFile.h"
+
+//*****************************************************************************
+//*****************************************************************************
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int JZAsciiRead::Open(const char* pFileName)
+{
+ int TrackCount, TicksPerQuarter;
+ if (
+ fscanf(
+ mpFd,
+ "Tracks %d, TicksPerQuarter %d\n",
+ &TrackCount,
+ &TicksPerQuarter) != 2)
+ {
+ return 0;
+ }
+ return TrackCount;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+JZEvent* JZAsciiRead::Read()
+{
+ JZEvent* pEvent = 0;
+
+ long Clock;
+ int sta, cha, Length;
+ if (fscanf(mpFd, "%6lu %02x %2d %d ", &Clock, &sta, &cha, &Length) != 4)
+ {
+ return pEvent;
+ }
+
+ unsigned char* pBuffer = new unsigned char[Length];
+ for (int i = 0; i < Length; ++i)
+ {
+ int d;
+ fscanf(mpFd, "%02x ", &d);
+ pBuffer[i] = (unsigned char)d;
+ }
+
+ switch (sta)
+ {
+ case StatUnknown:
+ break;
+
+ case StatKeyOff:
+ pEvent = new tKeyOff(Clock, cha, pBuffer[0]);
+ break;
+
+ case StatKeyOn:
+ pEvent = new tKeyOn(Clock, cha, pBuffer[0], pBuffer[1]);
+ break;
+
+ case StatControl:
+ pEvent = new tControl(Clock, cha, pBuffer[0], pBuffer[1]);
+ break;
+
+ case StatPitch:
+ pEvent = new tPitch(Clock, cha, pBuffer[0], pBuffer[1]);
+ break;
+
+ case StatProgram:
+ pEvent = new tProgram(Clock, cha, pBuffer[0]);
+ break;
+
+ case StatText:
+ pEvent = new tText(Clock, pBuffer, Length);
+ break;
+
+ case StatTrackName:
+ pEvent = new tTrackName(Clock, pBuffer, Length);
+ break;
+
+ case StatMarker:
+ pEvent = new tMarker(Clock, pBuffer, Length);
+ break;
+
+ case StatEndOfTrack:
+ break;
+
+ case StatSetTempo:
+ pEvent = new tSetTempo(Clock, pBuffer[0], pBuffer[1], pBuffer[2]);
+ break;
+
+ case StatTimeSignat:
+ pEvent = new tTimeSignat(
+ Clock,
+ pBuffer[0],
+ pBuffer[1],
+ pBuffer[2],
+ pBuffer[3]);
+ break;
+
+ case StatSysEx:
+ pEvent = new tSysEx(Clock, pBuffer, Length);
+ break;
+ }
+
+ delete [] pBuffer;
+
+ return pEvent;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int JZAsciiRead::NextTrack()
+{
+ return fscanf(mpFd, "NextTrack\n") == 0;
+}
+
+//*****************************************************************************
+// Description:
+// Ascii-Output (debug)
+//*****************************************************************************
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int JZAsciiWrite::Open(
+ const char* pFileName,
+ int TrackCount,
+ int TicksPerQuarter)
+{
+ if (!JZWriteBase::Open(pFileName, TrackCount, TicksPerQuarter))
+ {
+ return 0;
+ }
+
+ fprintf(
+ mpFd,
+ "Tracks %d, TicksPerQuarter %d\n",
+ TrackCount,
+ TicksPerQuarter);
+
+ return TrackCount;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int JZAsciiWrite::Write(JZEvent* pEvent, unsigned char* pData, int Length)
+{
+ tChannelEvent *ce;
+
+ fprintf(mpFd, "%6ld %02x ", pEvent->GetClock(), pEvent->Stat);
+ if ((ce = pEvent->IsChannelEvent()) != 0)
+ {
+ fprintf(mpFd, "%2d ", ce->Channel);
+ }
+ else
+ {
+ fprintf(mpFd, "-1 ");
+ }
+
+ fprintf(mpFd, "%d ", Length);
+ for (int i = 0; i < Length; ++i)
+ {
+ fprintf(mpFd, "%02x ", pData[i]);
+ }
+ fprintf(mpFd, "\n");
+
+ return 0;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void JZAsciiWrite::NextTrack()
+{
+ fprintf(mpFd, "NextTrack\n");
+}
Property changes on: trunk/jazz/src/AsciiMidiFile.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/jazz/src/AsciiMidiFile.h
===================================================================
--- trunk/jazz/src/AsciiMidiFile.h (rev 0)
+++ trunk/jazz/src/AsciiMidiFile.h 2008-03-30 15:37:16 UTC (rev 374)
@@ -0,0 +1,57 @@
+//*****************************************************************************
+// The JAZZ++ Midi Sequencer
+//
+// Copyright (C) 1994-2000 Andreas Voss and Per Sigmond, all rights reserved.
+// Modifications Copyright (C) 2008 Peter J. Stieber
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+//*****************************************************************************
+
+#ifndef JZ_ASCIIMIDIFILE_H
+#define JZ_ASCIIMIDIFILE_H
+
+#include "Events.h"
+
+//*****************************************************************************
+//*****************************************************************************
+class JZAsciiRead : public JZReadBase
+{
+ public:
+
+ virtual int Open(const char* pFileName);
+
+ virtual JZEvent* Read();
+
+ virtual int NextTrack();
+};
+
+//*****************************************************************************
+//*****************************************************************************
+class JZAsciiWrite : public JZWriteBase
+{
+ public:
+
+ virtual int Open(
+ const char* pFileName,
+ int TrackCount,
+ int TicksPerQuarter);
+
+ virtual int Write(JZEvent* pEvent, unsigned char* pData, int Length);
+
+ virtual void NextTrack();
+};
+
+
+#endif // !defined(JZ_ASCIIMIDIFILE_H)
Property changes on: trunk/jazz/src/AsciiMidiFile.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/jazz/src/Makefile.am
===================================================================
--- trunk/jazz/src/Makefile.am 2008-03-30 15:21:52 UTC (rev 373)
+++ trunk/jazz/src/Makefile.am 2008-03-30 15:37:16 UTC (rev 374)
@@ -7,6 +7,7 @@
AlsaDriver.cpp \
AlsaPlayer.cpp \
AlsaThru.cpp \
+AsciiMidiFile.cpp \
Audio.cpp \
AudioDriver.cpp \
ClockDialog.cpp \
@@ -80,6 +81,7 @@
AlsaDriver.h \
AlsaPlayer.h \
AlsaThru.h \
+AsciiMidiFile.h \
Audio.h \
AudioDriver.h \
ClockDialog.h \
Modified: trunk/jazz/vc8/JazzPlusPlus-VC8.vcproj
===================================================================
--- trunk/jazz/vc8/JazzPlusPlus-VC8.vcproj 2008-03-30 15:21:52 UTC (rev 373)
+++ trunk/jazz/vc8/JazzPlusPlus-VC8.vcproj 2008-03-30 15:37:16 UTC (rev 374)
@@ -229,6 +229,14 @@
>
</File>
<File
+ RelativePath="..\src\AsciiMidiFile.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\src\AsciiMidiFile.h"
+ >
+ </File>
+ <File
RelativePath="..\src\Audio.cpp"
>
</File>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|