Skip to content

Commit

Permalink
Another update
Browse files Browse the repository at this point in the history
- Added more chords
- Fixed window size
- Ability to reset instrument state to previous
- States of Deep Tremolo and Deep Vibrato, and recently opened/saved file now are remembering
- Ability to drop file into the window to open it
- Ability to open file from command line argument
- Better poliphony: now used all 18 2-operator channels and 6 4-operator channels
- Question on saving a modified file
  • Loading branch information
Wohlstand committed Jun 10, 2016
1 parent 20e569e commit a1034a0
Show file tree
Hide file tree
Showing 11 changed files with 1,378 additions and 1,069 deletions.
2 changes: 0 additions & 2 deletions FileFormats/junlevizion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

#include <QFile>
/*
* OPL Bank Editor by Wohlstand, a free tool for music bank editing
* Copyright (c) 2016 Vitaly Novichkov <admin@wohlnet.ru>
Expand Down
15 changes: 14 additions & 1 deletion audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ void BankEditor::initAudio()
connect(ui->testMinor, SIGNAL(pressed()), m_generator, SLOT(PlayMinorChord()));
connect(ui->testMinor, SIGNAL(released()), m_generator, SLOT(NoteOffAllChans()));

connect(ui->testAugmented, SIGNAL(pressed()), m_generator, SLOT(PlayAugmentedChord()));
connect(ui->testAugmented, SIGNAL(released()), m_generator, SLOT(NoteOffAllChans()));

connect(ui->testDiminished, SIGNAL(pressed()), m_generator, SLOT(PlayDiminishedChord()));
connect(ui->testDiminished, SIGNAL(released()), m_generator, SLOT(NoteOffAllChans()));

connect(ui->testMajor7, SIGNAL(pressed()), m_generator, SLOT(PlayMajor7Chord()));
connect(ui->testMajor7, SIGNAL(released()), m_generator, SLOT(NoteOffAllChans()));

connect(ui->testMinor7, SIGNAL(pressed()), m_generator, SLOT(PlayMinor7Chord()));
connect(ui->testMinor7, SIGNAL(released()), m_generator, SLOT(NoteOffAllChans()));

connect(ui->shutUp, SIGNAL(clicked()), m_generator, SLOT(Silence()));

connect(ui->noteToTest, SIGNAL(valueChanged(int)), m_generator, SLOT(changeNote(int)));
m_generator->changeNote(ui->noteToTest->value());

Expand All @@ -68,7 +82,6 @@ void BankEditor::initAudio()
m_pushTimer.start(4);
}


void BankEditor::pushTimerExpired()
{
if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState)
Expand Down
16 changes: 15 additions & 1 deletion bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,25 @@ FmBank::FmBank()

FmBank::FmBank(const FmBank &fb)
{
int size=sizeof(Instrument)*128;
int size = sizeof(Instrument)*128;
memcpy(Ins_Melodic, fb.Ins_Melodic, size);
memcpy(Ins_Percussion, fb.Ins_Percussion, size);
}

bool FmBank::operator==(const FmBank &fb)
{
int size = sizeof(Instrument)*128;
bool res = true;
res &= (memcmp(Ins_Melodic, fb.Ins_Melodic, size)==0);
res &= (memcmp(Ins_Percussion, fb.Ins_Percussion, size)==0);
return res;
}

bool FmBank::operator!=(const FmBank &fb)
{
return !this->operator==(fb);
}

void FmBank::reset()
{
int size=sizeof(Instrument)*128;
Expand Down
2 changes: 2 additions & 0 deletions bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class FmBank
public:
FmBank();
FmBank(const FmBank &fb);
bool operator==(const FmBank &fb);
bool operator!=(const FmBank &fb);

/**
* @brief Set everything to zero
Expand Down
215 changes: 170 additions & 45 deletions bank_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>

#include <QMimeData>

#include "bank_editor.h"
#include "ui_bank_editor.h"
Expand All @@ -31,6 +34,7 @@ BankEditor::BankEditor(QWidget *parent) :
{
memset(&m_clipboard, 0, sizeof(FmBank::Instrument));
m_curInst = NULL;
m_curInstBackup = NULL;
m_lock = false;

ui->setupUi(this);
Expand All @@ -43,7 +47,13 @@ BankEditor::BankEditor(QWidget *parent) :

m_buffer.resize(8192);
m_buffer.fill(0, 8192);

this->setWindowFlags(Qt::WindowTitleHint|Qt::WindowSystemMenuHint|
Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint);
this->setFixedSize(this->window()->width(), this->window()->height());

initAudio();
loadSettings();
}

BankEditor::~BankEditor()
Expand All @@ -56,63 +66,165 @@ BankEditor::~BankEditor()
delete ui;
}

void BankEditor::loadSettings()
{
QApplication::setOrganizationName(_COMPANY);
QApplication::setOrganizationDomain(_PGE_URL);
QApplication::setApplicationName("OPL FM Banks Editor");
QSettings setup;
ui->deepTremolo->setChecked(setup.value("deep-tremolo", false).toBool());
ui->deepVibrato->setChecked(setup.value("deep-vibrato", false).toBool());
m_recentPath = setup.value("recent-path").toString();
}

void BankEditor::saveSettings()
{
QSettings setup;
setup.setValue("deep-tremolo", ui->deepTremolo->isChecked());
setup.setValue("deep-vibrato", ui->deepVibrato->isChecked());
setup.setValue("recent-path", m_recentPath);
}



void BankEditor::on_actionNew_triggered()
void BankEditor::closeEvent(QCloseEvent *event)
{
ui->currentFile->setText(tr("<Untitled>"));
m_bank.reset();
on_instruments_currentItemChanged(NULL, NULL);
if(m_bank != m_bankBackup)
{
QMessageBox::StandardButton res = QMessageBox::question(this, tr("File is not saved"), tr("File is modified and not saved. Do you want to save it?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
if((res==QMessageBox::Cancel) || (res==QMessageBox::NoButton))
{
event->ignore();
return;
}
else
if(res==QMessageBox::Yes)
{
if(!saveFileAs())
{
event->ignore();
return;
}
}
}
saveSettings();
}

void BankEditor::on_actionOpen_triggered()
void BankEditor::dragEnterEvent(QDragEnterEvent *e)
{
QString fileToOpen;
fileToOpen = QFileDialog::getOpenFileName(this, "Open bank file", m_recentPath, "JunleVision bank (*.op3)");
if(fileToOpen.isEmpty())
return;
if (e->mimeData()->hasUrls())
{
e->acceptProposedAction();
}
}

void BankEditor::dropEvent(QDropEvent *e)
{
this->raise();
this->setFocus(Qt::ActiveWindowFocusReason);

foreach(const QUrl &url, e->mimeData()->urls())
{
const QString &fileName = url.toLocalFile();
if(openFile(fileName))
break; //Only first valid file!
}
}


bool BankEditor::openFile(QString filePath)
{
if(filePath.endsWith("op3", Qt::CaseInsensitive))
{
int err = JunleVizion::loadFile(filePath, m_bank);
if(err != JunleVizion::ERR_OK)
{
QString errText;
switch(err)
{
case JunleVizion::ERR_BADFORMAT: errText = "Bad file format"; break;
case JunleVizion::ERR_NOFILE: errText = "Can't open file"; break;
}
QMessageBox::warning(this, "Can't open bank file!", "Can't open bank file because "+errText, QMessageBox::Ok);
return false;
} else {
m_recentPath = filePath;
if(!ui->instruments->selectedItems().isEmpty())
on_instruments_currentItemChanged(ui->instruments->selectedItems().first(), NULL);
else
on_instruments_currentItemChanged(NULL, NULL);
ui->currentFile->setText(filePath);
m_bankBackup = m_bank;
return true;
}
}
return false;
}

int err = JunleVizion::loadFile(fileToOpen, m_bank);
if(err != JunleVizion::ERR_OK)
bool BankEditor::saveFile(QString filePath)
{
if(filePath.endsWith("op3", Qt::CaseInsensitive))
{
QString errText;
switch(err)
int err = JunleVizion::saveFile(filePath, m_bank);
if(err != JunleVizion::ERR_OK)
{
case JunleVizion::ERR_BADFORMAT: errText = "Bad file format"; break;
case JunleVizion::ERR_NOFILE: errText = "Can't open file"; break;
QString errText;
switch(err)
{
case JunleVizion::ERR_NOFILE: errText = "Can't open file for write!"; break;
}
QMessageBox::warning(this, "Can't save bank file!", "Can't save bank file because "+errText, QMessageBox::Ok);
return false;
} else {
ui->currentFile->setText(filePath);
m_recentPath = filePath;
m_bankBackup = m_bank;
return true;
}
QMessageBox::warning(this, "Can't open bank file!", "Can't open bank file because "+errText, QMessageBox::Ok);
} else {
m_recentPath = fileToOpen;
if(!ui->instruments->selectedItems().isEmpty())
on_instruments_currentItemChanged(ui->instruments->selectedItems().first(), NULL);
else
on_instruments_currentItemChanged(NULL, NULL);
ui->currentFile->setText(fileToOpen);
}
return false;
}

void BankEditor::on_actionSave_triggered()
bool BankEditor::saveFileAs()
{
QString fileToSave;
fileToSave = QFileDialog::getSaveFileName(this, "Save bank file", m_recentPath, "JunleVision bank (*.op3)");
if(fileToSave.isEmpty())
return;
return false;
return saveFile(fileToSave);
}

int err = JunleVizion::saveFile(fileToSave, m_bank);
if(err != JunleVizion::ERR_OK)
void BankEditor::flushInstrument()
{
loadInstrument();
if( m_curInst && ui->percussion->isChecked() )
{
QString errText;
switch(err)
{
case JunleVizion::ERR_NOFILE: errText = "Can't open file for write!"; break;
}
QMessageBox::warning(this, "Can't save bank file!", "Can't save bank file because "+errText, QMessageBox::Ok);
} else {
ui->currentFile->setText(fileToSave);
ui->noteToTest->setValue( m_curInst->percNoteNum );
}
sendPatch();
}

void BankEditor::on_actionNew_triggered()
{
ui->currentFile->setText(tr("<Untitled>"));
m_bank.reset();
m_bankBackup.reset();
on_instruments_currentItemChanged(NULL, NULL);
}

void BankEditor::on_actionOpen_triggered()
{
QString fileToOpen;
fileToOpen = QFileDialog::getOpenFileName(this, "Open bank file", m_recentPath, "JunleVision bank (*.op3)");
if(fileToOpen.isEmpty())
return;

openFile(fileToOpen);
}

void BankEditor::on_actionSave_triggered()
{
saveFileAs();
}

void BankEditor::on_actionExit_triggered()
Expand All @@ -132,13 +244,27 @@ void BankEditor::on_actionPaste_triggered()
if(!m_curInst) return;

memcpy(m_curInst, &m_clipboard, sizeof(FmBank::Instrument));
flushInstrument();
}

loadInstrument();
if( m_curInst && ui->percussion->isChecked() )
void BankEditor::on_actionReset_current_instrument_triggered()
{
if(!m_curInstBackup || !m_curInst)
return; //Some pointer is Null!!!

if( memcmp(m_curInst, m_curInstBackup, sizeof(FmBank::Instrument))==0 )
return; //Nothing to do

if( QMessageBox::Yes == QMessageBox::question(this,
tr("Reset instrument to initial state"),
tr("This instrument will be reseted to initial state "
"(sice this file loaded or saved).\n"
"Are you wish to continue?"),
QMessageBox::Yes|QMessageBox::No) )
{
ui->noteToTest->setValue( m_curInst->percNoteNum );
memcpy(m_curInst, m_curInstBackup, sizeof(FmBank::Instrument));
flushInstrument();
}
sendPatch();
}


Expand All @@ -165,18 +291,14 @@ void BankEditor::on_instruments_currentItemChanged(QListWidgetItem *current, QLi
ui->curInsInfo->setText(QString("%1 - %2").arg(current->data(Qt::UserRole).toInt()).arg(current->text()));
setCurrentInstrument(current->data(Qt::UserRole).toInt(), ui->percussion->isChecked() );
}
loadInstrument();
if( m_curInst && ui->percussion->isChecked() )
{
ui->noteToTest->setValue( m_curInst->percNoteNum );
}
sendPatch();
flushInstrument();
}


void BankEditor::setCurrentInstrument(int num, bool isPerc)
{
m_curInst = isPerc ? &m_bank.Ins_Percussion[num] : &m_bank.Ins_Melodic[num];
m_curInstBackup = isPerc ? &m_bankBackup.Ins_Percussion[num] : &m_bankBackup.Ins_Melodic[num];
}

void BankEditor::loadInstrument()
Expand Down Expand Up @@ -319,3 +441,6 @@ void BankEditor::setDrums()
}
}




Loading

0 comments on commit a1034a0

Please sign in to comment.