I've got enough of this. It works good enough and saves me some time.
Next revision will probably be bug fixing :)
Vlada
Index: /home/vlada/sources/rg_experiment/src/gui/dialogs/ImportDeviceDialog.cpp
===================================================================
--- /home/vlada/sources/rg_experiment/src/gui/dialogs/ImportDeviceDialog.cpp
(revision 11325)
+++ /home/vlada/sources/rg_experiment/src/gui/dialogs/ImportDeviceDialog.cpp
(working copy)
@@ -44,6 +44,7 @@
#include <QHBoxLayout>
#include <QButtonGroup>
+#include <string>
namespace Rosegarden
{
@@ -441,7 +442,6 @@
return true;
}
-///Change function!!!!
bool
ImportDeviceDialog::importFromLSCP(QString filename)
{
@@ -451,34 +451,33 @@
std::vector<MidiBank> banks;
std::vector<MidiProgram> programs;
+ int comparableBankNumber = 0;
+
for (LSCPPatchExtractor::Device::const_iterator i = lscpDevice.begin();
- i != lscpDevice.end(); ++i) {
+ i != lscpDevice.end(); ++i) {
- int bankNumber = i->first;
- const LSCPPatchExtractor::Bank &lscpBank = i->second;
+ int bankNumber = (*i).bankNumber; //Local variable bankNumber gets
value from struct's member bankNumber
+ std::string bankName = (*i).bankName; //Local variable bankName gets
value from struct's member bankName
int msb = bankNumber / 128;
int lsb = bankNumber % 128;
- MidiBank bank
- (msb == 1, msb, lsb,
- qstrtostr(tr("Bank %1:%2").arg(msb).arg(lsb)));
+ MidiBank bank (msb == 1, msb, lsb, bankName);
- banks.push_back(bank);
-
- for (LSCPPatchExtractor::Bank::const_iterator j = lscpBank.begin();
- j != lscpBank.end(); ++j) {
-
- MidiProgram program(bank, j->first, j->second);
- programs.push_back(program);
+ if (comparableBankNumber != bankNumber) {
+ banks.push_back(bank);
+ comparableBankNumber = bankNumber;
}
+
+ MidiProgram program(bank, (*i).programNumber, (*i).programName);
+ programs.push_back(program);
}
// This is a temporary device, so we can use device and instrument
// IDs that other devices in the Studio may also be using without
// expecting any problems
MidiDevice *device = new MidiDevice
- (0, MidiInstrumentBase, "", MidiDevice::Play);
+ (0, MidiInstrumentBase, "", MidiDevice::Play);
device->replaceBankList(banks);
device->replaceProgramList(programs);
m_devices.push_back(device);
Index: /home/vlada/sources/rg_experiment/src/sound/LSCPPatchExtractor.h
===================================================================
--- /home/vlada/sources/rg_experiment/src/sound/LSCPPatchExtractor.h
(revision 11325)
+++ /home/vlada/sources/rg_experiment/src/sound/LSCPPatchExtractor.h
(working copy)
@@ -23,6 +23,7 @@
#include <map>
#include <string>
+#include <vector>
class QString;
@@ -34,9 +35,16 @@
{
public:
- typedef std::map<int, std::string> Bank;
- typedef std::map<int, Bank> Device;
+ typedef struct lscp_bank_program_data {
+ int bankNumber;
+ std::string bankName;
+ int programNumber;
+ std::string programName;
+ } Bank_Prog;
+
+ typedef std::vector<Bank_Prog> Device;
+
static bool isLSCPFile(const QString& fileName);
static Device extractContent(const QString& fileName);
Index: /home/vlada/sources/rg_experiment/src/sound/LSCPPatchExtractor.cpp
===================================================================
--- /home/vlada/sources/rg_experiment/src/sound/LSCPPatchExtractor.cpp
(revision 11325)
+++ /home/vlada/sources/rg_experiment/src/sound/LSCPPatchExtractor.cpp
(working copy)
@@ -55,16 +55,19 @@
LSCPPatchExtractor::Device
LSCPPatchExtractor::extractContent(const QString& fileName)
{
- std::cout << "Usao sam u extractContent u LSCPParser-u!" << std::endl;
+/////// Works for single device midi mappings!
+
Device device;
QFile lscpFile(fileName);
QTextStream inStream(&lscpFile);
+
QStringList splitLine;
-
+
unsigned int bank, program;
std::string programName;
-// std::string deviceName;
+ std::string bankName;
+ std::string tempDeviceName, tempBankName;
if (!lscpFile.open(QFile::ReadOnly)) {
return device;
@@ -73,43 +76,59 @@
QString currentLine = inStream.readLine();
currentLine = currentLine.simplified();
+ Bank_Prog currentDevice;
+
if (!currentLine.isEmpty() && currentLine.startsWith("add",
Qt::CaseInsensitive)) {
-// Preparation for returning device's name - do nothing for now!
+
+///// Useless for now. Will be needed if someone dedicates time to implement
Device import!
+// std::cout << "Usao sam u ADD!";
//
-// splitLine = currentLine.split(QRegExp("\\s+"));
-// deviceName = splitLine.at(2).latin1();
+// splitLine = splitQuotedString(currentLine);
+// tempDeviceName = splitLine.at(2).latin1();
+// //debug
+// for (int i = 0; i < splitLine.size(); i++) std::cout <<
splitLine.at(i) << std::endl;
+// std::cout << " " << tempDeviceName << std::endl;
} else if (!currentLine.isEmpty() && currentLine.startsWith("map",
Qt::CaseInsensitive)) {
+// std::cout << "Usao sam u MAP!";
+
unsigned int positionOfBankElement = 3; //position of element
in QStringList if NON_MODAL element is absent
unsigned int positionOfProgramElement = 4; //similar to above
+ unsigned int positionOfPatchFileName = 6; //we extract bank
name from filesystem's file name.
splitLine = splitQuotedString(currentLine);
-// std::cout << splitLine.size() << std::endl;
-// for (int i = 0; i < splitLine.size(); i++) {
-// std::cout << i << ": " << splitLine.at(i) << std::endl;
-// }
if (splitLine.at(2) == "NON_MODAL") {
-// std::cout << " Ima non_modal" << std::endl;
-// Shifting position of elements if optional element is present
+ // Shifting position of elements if optional element (NON
MODAL) is present
positionOfBankElement = 4;
positionOfProgramElement = 5;
+ positionOfPatchFileName = 7;
}
- bank = splitLine.at(positionOfBankElement).toInt();
- program = splitLine.at(positionOfProgramElement).toInt();
-
+ //Getting bank name HACK!!! Not in specification, so we use
filename!
+ QString patchFileName = splitLine.at(positionOfPatchFileName);
+ QStringList splitPatchFileName = patchFileName.split("/");
+ QString temp =
splitPatchFileName.at(splitPatchFileName.size()-1);
+ temp = temp.replace("x20"," ");
+ temp = temp.remove(".gig");
+
+ currentDevice.bankName = temp.latin1();
+ currentDevice.bankNumber =
splitLine.at(positionOfBankElement).toInt();
+ currentDevice.programNumber =
splitLine.at(positionOfProgramElement).toInt();
+
QString quotedName = splitLine.at(splitLine.size() - 1);
-// std::cout << splitLine.at(splitLine.size() - 1).latin1() <<
std::cout;
-// Chacking for another optional element. This one is even more strange -
program name may be absent as well!
- if (quotedName.isEmpty() || quotedName.contains("ON_DEMAND")
|| quotedName.contains("ON_DEMAND_HOLD") || quotedName.contains("PERSISTENT")) {
- programName = "Unnamed instrument";
+ // Chacking for another optional element. This one is even
more strange - program name may be absent as well!
+ if (quotedName.isEmpty() ||
+ quotedName.contains("ON_DEMAND") ||
+ quotedName.contains("ON_DEMAND_HOLD") ||
+ quotedName.contains("PERSISTENT")) {
+ currentDevice.programName = "Unnamed instrument";
} else {
- programName = quotedName.latin1();
+ currentDevice.programName = quotedName.latin1();
}
- device[bank][program] = programName;
+ device.push_back(currentDevice);
}
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Rosegarden-devel mailing list
[email protected] - use the link below to unsubscribe
https://lists.sourceforge.net/lists/listinfo/rosegarden-devel