Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy-pasting between multiple instances of MidiEditor #102

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Sola85
Copy link

@Sola85 Sola85 commented Sep 18, 2022

This is currently not possible as copied events are simply stored in a variable of each instance of MidiEditor.

I added this feature by converting the selected events into a MidiFile object and saving this in QSharedMemory.
When pasting, the reverse happens. See the commit message and the subsequent comment for more details.

This would resolve #84.

@Sola85
Copy link
Author

Sola85 commented Sep 20, 2022

Fixed tempo not being preseved across windows

@@ -37,6 +37,7 @@
#include "math.h"

#include <QtCore/qmath.h>
#include <iostream>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classes and functions ain't used anywhere in that file

channels[i] = new MidiChannel(this, i);
}

QDataStream* stream = new QDataStream(raw_midi);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add constructor from QDataStream to avoid code duplication

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. There was already some duplication present before. Would probably make sense to fix all of this at once.

MidiFile(QString path, bool* ok, QStringList* log = 0);
MidiFile();
// needed to protocol fileLength
MidiFile(int maxTime, Protocol* p);
bool save(QString path);
QByteArray writeDeltaTime(int time);
QByteArray toByteArray();
static QByteArray writeDeltaTime(int time);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really should be static?


if (copiedEvents->size() == 0) {
if(!ok){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine... But how it can be false? Okay...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should never be false, but since the MidiFile constructor already has a check-mechanism, why not use it


QByteArray copyFileBytes = copyFile.toByteArray();
int MAX_COPY_SIZE = 1073741824; //1GB
if (copyFileBytes.size() > MAX_COPY_SIZE){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have any MAX_COPY_SIZE? Is it a restriction of QSharedMemory or something?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create buffer of some size, so we should set some size, MAX_COPY_SIZE in our case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size of QSharedMemory needs to be specified before allocation, as far as i know. One can of course argue about what this size should be...

@NamVr
Copy link

NamVr commented Dec 10, 2024

This would be a very cool feature to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable copy and pasting events between multiple instances of MidiEditor
3 participants