From 3948032d0a2e439069d9a6859f7f35eebb54944d Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Wed, 25 May 2011 17:27:35 +0000 Subject: added step recording for drum edit step-recording stuff has been put into a easy-to-use StepRec class the midi-in and step-rec buttons are now fully functional again --- muse2/muse/midiedit/dcanvas.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'muse2/muse/midiedit/dcanvas.h') diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h index b86bc2d7..5a1fefeb 100644 --- a/muse2/muse/midiedit/dcanvas.h +++ b/muse2/muse/midiedit/dcanvas.h @@ -10,6 +10,7 @@ #include "ecanvas.h" #include "song.h" +#include "steprec.h" #define TH 18 @@ -40,7 +41,9 @@ class PianoRoll; //--------------------------------------------------------- class DrumCanvas : public EventCanvas { - + + StepRec* steprec; + // Cursor tool position QPoint cursorPos; int _stepSize; @@ -77,6 +80,9 @@ class DrumCanvas : public EventCanvas { signals: void newWidth(int); + private slots: + void midiNote(int pitch, int velo); + public slots: void mapChanged(int, int); void keyPressed(int, int); -- cgit v1.2.3 From 25a43d58dead31caf482fc8ada4f231d2f1269d9 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 29 May 2011 12:43:17 +0000 Subject: - moved cut,copy'n'paste to functions.cpp, removed unneccessary duplication - changed behaviour of paste: now the pasted, not the original notes are selected --- muse2/ChangeLog | 3 + muse2/muse/functions.cpp | 157 ++++++++++++++++++++++++++ muse2/muse/functions.h | 8 ++ muse2/muse/midiedit/dcanvas.cpp | 230 +------------------------------------- muse2/muse/midiedit/dcanvas.h | 2 - muse2/muse/midiedit/drumedit.cpp | 9 ++ muse2/muse/midiedit/ecanvas.cpp | 135 +--------------------- muse2/muse/midiedit/ecanvas.h | 3 - muse2/muse/midiedit/pianoroll.cpp | 9 ++ muse2/muse/midiedit/prcanvas.cpp | 226 +------------------------------------ muse2/muse/midiedit/prcanvas.h | 2 - muse2/muse/midiedit/scoreedit.cpp | 7 +- 12 files changed, 197 insertions(+), 594 deletions(-) (limited to 'muse2/muse/midiedit/dcanvas.h') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index aac27cc3..9f7d2e07 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,6 @@ +29.05.2011: + - moved cut,copy'n'paste to functions.cpp, removed unneccessary duplication (flo93) + - changed behaviour of paste: now the pasted, not the original notes are selected (flo93) 28.05.2011: - fixed dragging and resizing of track header, also changed default index of new sections, they should appear last now (rj) diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp index 5677bcfd..94b7a52d 100644 --- a/muse2/muse/functions.cpp +++ b/muse2/muse/functions.cpp @@ -14,8 +14,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include + using namespace std; @@ -604,6 +614,153 @@ void legato(const set& parts, int range, int min_len, bool dont_shorten) +void copy_notes(const set& parts, int range) +{ + QMimeData* drag = selected_events_to_mime(parts,range); + + if (drag) + QApplication::clipboard()->setMimeData(drag, QClipboard::Clipboard); +} + +void paste_notes(Part* dest_part) +{ + QString tmp="x-muse-eventlist"; // QClipboard::text() expects a QString&, not a QString :( + QString s = QApplication::clipboard()->text(tmp, QClipboard::Clipboard); // TODO CHECK Tim. + paste_at(dest_part, s, song->cpos()); +} + +QMimeData* selected_events_to_mime(const set& parts, int range) +{ + map events=get_events(parts,range); + + //--------------------------------------------------- + // generate event list from selected events + //--------------------------------------------------- + + EventList el; + unsigned startTick = MAXINT; //will be the tick of the first event or MAXINT if no events are there + + for (map::iterator it=events.begin(); it!=events.end(); it++) + { + Event& e = *it->first; + + if (e.tick() < startTick) + startTick = e.tick(); + + el.add(e); + } + + //--------------------------------------------------- + // write events as XML into tmp file + //--------------------------------------------------- + + FILE* tmp = tmpfile(); + if (tmp == 0) + { + fprintf(stderr, "EventCanvas::getTextDrag() fopen failed: %s\n", strerror(errno)); + return 0; + } + + Xml xml(tmp); + int level = 0; + + xml.tag(level++, "eventlist"); + for (ciEvent e = el.begin(); e != el.end(); ++e) + e->second.write(level, xml, -startTick); + xml.etag(--level, "eventlist"); + + //--------------------------------------------------- + // read tmp file into drag Object + //--------------------------------------------------- + + fflush(tmp); + struct stat f_stat; + if (fstat(fileno(tmp), &f_stat) == -1) + { + fprintf(stderr, "PianoCanvas::copy() fstat failed:<%s>\n", + strerror(errno)); + fclose(tmp); + return 0; + } + int n = f_stat.st_size; + char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fileno(tmp), 0); + fbuf[n] = 0; + + QByteArray data(fbuf); + QMimeData* md = new QMimeData(); + + md->setData("text/x-muse-eventlist", data); + + munmap(fbuf, n); + fclose(tmp); + + return md; +} + +void paste_at(Part* dest_part, const QString& pt, int pos) +{ + Xml xml(pt.toLatin1().constData()); + for (;;) + { + Xml::Token token = xml.parse(); + const QString& tag = xml.s1(); + switch (token) + { + case Xml::Error: + case Xml::End: + return; + + case Xml::TagStart: + if (tag == "eventlist") + { + song->startUndo(); + EventList el; + el.read(xml, "eventlist", true); + int modified = SC_EVENT_INSERTED; + for (iEvent i = el.begin(); i != el.end(); ++i) + { + Event e = i->second; + int tick = e.tick() + pos - dest_part->tick(); + if (tick<0) + { + printf("ERROR: trying to add event before current part!\n"); + song->endUndo(SC_EVENT_INSERTED); + return; + } + + e.setTick(tick); + e.setSelected(true); + int diff = e.endTick()-dest_part->lenTick(); + if (diff > 0) // too short part? extend it + { + Part* newPart = dest_part->clone(); + newPart->setLenTick(newPart->lenTick()+diff); + // Indicate no undo, and do port controller values but not clone parts. + audio->msgChangePart(dest_part, newPart, false, true, false); + modified=modified|SC_PART_MODIFIED; + dest_part = newPart; // reassign TODO FINDME does this work, or has dest_part to be a nonconst reference? + } + // Indicate no undo, and do not do port controller values and clone parts. + audio->msgAddEvent(e, dest_part, false, false, false); + } + song->endUndo(modified); + return; + } + else + xml.unknown("pasteAt"); + break; + + case Xml::Attribut: + case Xml::TagEnd: + default: + break; + } + } +} + + + void read_function_dialog_config(Xml& xml) { if (erase_dialog==NULL) diff --git a/muse2/muse/functions.h b/muse2/muse/functions.h index 40e5f0e0..b08c2c39 100644 --- a/muse2/muse/functions.h +++ b/muse2/muse/functions.h @@ -22,6 +22,8 @@ #include #include "part.h" +class QString; +class QMimeData; extern GateTime* gatetime_dialog; extern Velocity* velocity_dialog; @@ -68,6 +70,12 @@ bool delete_overlaps(const std::set& parts); bool legato(const std::set& parts); +//functions for copy'n'paste +void copy_notes(const std::set& parts, int range); +void paste_notes(Part* dest_part); +QMimeData* selected_events_to_mime(const std::set& parts, int range); +void paste_at(Part* dest_part, const QString& pt, int pos); + //functions for reading and writing default values class Xml; diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index 4f904be1..89cb1e4c 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -34,6 +34,7 @@ #include "audio.h" #include "shortcuts.h" #include "icons.h" +#include "functions.h" #define CARET 10 #define CARET2 5 @@ -652,27 +653,7 @@ int DrumCanvas::pitch2y(int pitch) const void DrumCanvas::cmd(int cmd) { - switch(cmd) { - case CMD_CUT: - copy(); - song->startUndo(); - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - DEvent* e = (DEvent*)(i->second); - Event event = e->event(); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(event, e->part(), false); - audio->msgDeleteEvent(event, e->part(), false, false, false); - } - song->endUndo(SC_EVENT_REMOVED); - break; - case CMD_COPY: - copy(); - break; - case CMD_PASTE: - paste(); - break; + switch (cmd) { case CMD_SELECT_ALL: // select all for (iCItem k = items.begin(); k != items.end(); ++k) { if (!k->second->isSelected()) @@ -814,158 +795,7 @@ void DrumCanvas::cmd(int cmd) redraw(); } -/* -//--------------------------------------------------------- -// getTextDrag -//--------------------------------------------------------- - -Q3TextDrag* DrumCanvas::getTextDrag(QWidget* parent) - { - //--------------------------------------------------- - // generate event list from selected events - //--------------------------------------------------- - - EventList el; - unsigned startTick = MAXINT; - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - DEvent* ne = (DEvent*)(i->second); - Event e = ne->event(); - if (startTick == MAXINT) - startTick = e.tick(); - el.add(e); - } - - //--------------------------------------------------- - // write events as XML into tmp file - //--------------------------------------------------- - - FILE* tmp = tmpfile(); - if (tmp == 0) { - fprintf(stderr, "EventCanvas::copy() fopen failed: %s\n", - strerror(errno)); - return 0; - } - Xml xml(tmp); - - int level = 0; - for (ciEvent e = el.begin(); e != el.end(); ++e) - e->second.write(level, xml, -startTick); - - //--------------------------------------------------- - // read tmp file into QTextDrag Object - //--------------------------------------------------- - - fflush(tmp); - struct stat f_stat; - if (fstat(fileno(tmp), &f_stat) == -1) { - fprintf(stderr, "EventCanvas::copy() fstat failes:<%s>\n", - strerror(errno)); - fclose(tmp); - return 0; - } - int n = f_stat.st_size; - char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, - MAP_PRIVATE, fileno(tmp), 0); - fbuf[n] = 0; - Q3TextDrag* drag = new Q3TextDrag(QString(fbuf), parent); - drag->setSubtype("eventlist"); - munmap(fbuf, n); - fclose(tmp); - return drag; - } -*/ - -//--------------------------------------------------------- -// copy -// cut copy paste -//--------------------------------------------------------- - -void DrumCanvas::copy() - { - QMimeData* md = getTextDrag(); - - if (md) - QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard); - } - -/* -//--------------------------------------------------------- -// paste -//--------------------------------------------------------- - -int DrumCanvas::pasteAt(const QString& pt, int pos) - { - QByteArray ba = pt.toLatin1(); - const char* p = ba.constData(); - Xml xml(p); - - // Added by T356. - int modified = SC_EVENT_INSERTED; - - song->startUndo(); - for (;;) { - Xml::Token token = xml.parse(); - QString tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - song->endUndo(modified); - return pos; - case Xml::TagStart: - if (tag == "event") { - Event e(Note); - e.read(xml); - - // Added by T356. - int tick = e.tick() + pos - curPart->tick(); - if (tick<0) { - printf("DrumCanvas::pasteAt ERROR: trying to add event before current part!\n"); - song->endUndo(SC_EVENT_INSERTED); - //delete el; - return pos; - } - e.setTick(tick); - int diff = e.endTick() - curPart->lenTick(); - if (diff > 0) {// too short part? extend it - Part* newPart = curPart->clone(); - newPart->setLenTick(newPart->lenTick()+diff); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(curPart, newPart, false, true, false); - - modified=modified|SC_PART_MODIFIED; - curPart = newPart; // reassign - } - - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(e, curPart, false, false, false); - } - else - xml.unknown("DCanvas::pasteAt"); - break; - case Xml::TagEnd: - default: - break; - } - } - } -*/ - -//--------------------------------------------------------- -// paste -// paste events -//--------------------------------------------------------- -void DrumCanvas::paste() - { - QString stype("x-muse-eventlist"); - - //QString s = QApplication::clipboard()->text(stype, QClipboard::Selection); - QString s = QApplication::clipboard()->text(stype, QClipboard::Clipboard); // TODO CHECK Tim. - - pasteAt(s, song->cpos()); - } //--------------------------------------------------------- // startDrag @@ -973,7 +803,7 @@ void DrumCanvas::paste() void DrumCanvas::startDrag(CItem* /* item*/, bool copymode) { - QMimeData* md = getTextDrag(); + QMimeData* md = selected_events_to_mime(partlist_to_set(editor->parts()), 1); if (md) { // QApplication::clipboard()->setData(drag, QClipboard::Clipboard); // This line NOT enabled in muse-1 @@ -1018,41 +848,6 @@ void DrumCanvas::dragLeaveEvent(QDragLeaveEvent*) { } -/* -//--------------------------------------------------------- -// dropEvent -//--------------------------------------------------------- - -void DrumCanvas::viewDropEvent(QDropEvent* event) - { - QString text; - if (event->source() == this) { - printf("local DROP\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - return; - } - //if (event->mimeData()->hasText()) { - if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { - - //text = event->mimeData()->text(); - text = QString(event->mimeData()->data("text/x-muse-eventlist")); - -// printf("drop <%s>\n", text.ascii()); - int x = editor->rasterVal(event->pos().x()); - if (x < 0) - x = 0; - pasteAt(text, x); - //event->accept(); // TODO - } - else { - printf("cannot decode drop\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - } - } -*/ - //--------------------------------------------------------- // keyPressed - called from DList //--------------------------------------------------------- @@ -1108,25 +903,6 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) typedef std::vector< std::pair >::iterator idel_ev; typedef std::vector< std::pair >::iterator iadd_ev; - /* - class delete_events : public std::vector< Part*, Event* > - { - public: - idel_ev find(Part* p, Event* e) - { - - }; - }; - class add_events : public std::vector< Part*, Event > - { - public: - iadd_ev find(Part* p, Event& e) - { - - }; - }; - */ - MidiTrackList* tracks = song->midis(); for (ciMidiTrack t = tracks->begin(); t != tracks->end(); t++) { MidiTrack* curTrack = *t; diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h index 5a1fefeb..364d9268 100644 --- a/muse2/muse/midiedit/dcanvas.h +++ b/muse2/muse/midiedit/dcanvas.h @@ -66,8 +66,6 @@ class DrumCanvas : public EventCanvas { int y2pitch(int y) const; int pitch2y(int pitch) const; - void copy(); - void paste(); void startDrag(CItem*, bool copymode); void dragEnterEvent(QDragEnterEvent* event); void dragMoveEvent(QDragMoveEvent*); diff --git a/muse2/muse/midiedit/drumedit.cpp b/muse2/muse/midiedit/drumedit.cpp index 4d2fae93..1e678432 100644 --- a/muse2/muse/midiedit/drumedit.cpp +++ b/muse2/muse/midiedit/drumedit.cpp @@ -903,6 +903,15 @@ void DrumEdit::reset() void DrumEdit::cmd(int cmd) { switch(cmd) { + case DrumCanvas::CMD_CUT: + copy_notes(partlist_to_set(parts()), 1); + erase_notes(partlist_to_set(parts()), 1); + break; + case DrumCanvas::CMD_COPY: copy_notes(partlist_to_set(parts()), 1); break; + case DrumCanvas::CMD_PASTE: + ((DrumCanvas*)canvas)->cmd(DrumCanvas::CMD_SELECT_NONE); + paste_notes(canvas->part()); + break; case DrumCanvas::CMD_LOAD: load(); break; case DrumCanvas::CMD_SAVE: save(); break; case DrumCanvas::CMD_RESET: reset(); break; diff --git a/muse2/muse/midiedit/ecanvas.cpp b/muse2/muse/midiedit/ecanvas.cpp index 7a421411..d41a383c 100644 --- a/muse2/muse/midiedit/ecanvas.cpp +++ b/muse2/muse/midiedit/ecanvas.cpp @@ -25,6 +25,7 @@ #include "event.h" #include "shortcuts.h" #include "audio.h" +#include "functions.h" //--------------------------------------------------------- // EventCanvas @@ -383,138 +384,6 @@ void EventCanvas::keyPress(QKeyEvent* event) event->ignore(); } -//--------------------------------------------------------- -// getTextDrag -//--------------------------------------------------------- - -//QDrag* EventCanvas::getTextDrag(QWidget* parent) -QMimeData* EventCanvas::getTextDrag() - { - //--------------------------------------------------- - // generate event list from selected events - //--------------------------------------------------- - - EventList el; - unsigned startTick = MAXINT; - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - ///NEvent* ne = (NEvent*)(i->second); - CItem* ne = i->second; - Event e = ne->event(); - if (startTick == MAXINT) - startTick = e.tick(); - el.add(e); - } - - //--------------------------------------------------- - // write events as XML into tmp file - //--------------------------------------------------- - - FILE* tmp = tmpfile(); - if (tmp == 0) { - fprintf(stderr, "EventCanvas::getTextDrag() fopen failed: %s\n", - strerror(errno)); - return 0; - } - Xml xml(tmp); - - int level = 0; - xml.tag(level++, "eventlist"); - for (ciEvent e = el.begin(); e != el.end(); ++e) - e->second.write(level, xml, -startTick); - xml.etag(--level, "eventlist"); - - //--------------------------------------------------- - // read tmp file into drag Object - //--------------------------------------------------- - - fflush(tmp); - struct stat f_stat; - if (fstat(fileno(tmp), &f_stat) == -1) { - fprintf(stderr, "PianoCanvas::copy() fstat failes:<%s>\n", - strerror(errno)); - fclose(tmp); - return 0; - } - int n = f_stat.st_size; - char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, - MAP_PRIVATE, fileno(tmp), 0); - fbuf[n] = 0; - - QByteArray data(fbuf); - QMimeData* md = new QMimeData(); - //QDrag* drag = new QDrag(parent); - - md->setData("text/x-muse-eventlist", data); - //drag->setMimeData(md); - - munmap(fbuf, n); - fclose(tmp); - - //return drag; - return md; - } - -//--------------------------------------------------------- -// pasteAt -//--------------------------------------------------------- - -void EventCanvas::pasteAt(const QString& pt, int pos) - { - QByteArray ba = pt.toLatin1(); - const char* p = ba.constData(); - Xml xml(p); - for (;;) { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - return; - case Xml::TagStart: - if (tag == "eventlist") { - song->startUndo(); - EventList* el = new EventList(); - el->read(xml, "eventlist", true); - int modified = SC_EVENT_INSERTED; - for (iEvent i = el->begin(); i != el->end(); ++i) { - Event e = i->second; - int tick = e.tick() + pos - curPart->tick(); - if (tick<0) { - printf("ERROR: trying to add event before current part!\n"); - song->endUndo(SC_EVENT_INSERTED); - delete el; - return; - } - - e.setTick(tick); - int diff = e.endTick()-curPart->lenTick(); - if (diff > 0) {// too short part? extend it - Part* newPart = curPart->clone(); - newPart->setLenTick(newPart->lenTick()+diff); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(curPart, newPart, false, true, false); - modified=modified|SC_PART_MODIFIED; - curPart = newPart; // reassign - } - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(e, curPart, false, false, false); - } - song->endUndo(modified); - delete el; - return; - } - else - xml.unknown("pasteAt"); - break; - case Xml::Attribut: - case Xml::TagEnd: - default: - break; - } - } - } //--------------------------------------------------------- // dropEvent @@ -535,7 +404,7 @@ void EventCanvas::viewDropEvent(QDropEvent* event) int x = editor->rasterVal(event->pos().x()); if (x < 0) x = 0; - pasteAt(text, x); + paste_at(curPart, text, x); //event->accept(); // TODO } else { diff --git a/muse2/muse/midiedit/ecanvas.h b/muse2/muse/midiedit/ecanvas.h index 86e1c200..0ae970ab 100644 --- a/muse2/muse/midiedit/ecanvas.h +++ b/muse2/muse/midiedit/ecanvas.h @@ -82,9 +82,6 @@ class EventCanvas : public Canvas { void range(int* s, int* e) const { *s = start_tick; *e = end_tick; } void playEvents(bool flag) { _playEvents = flag; } void selectAtTick(unsigned int tick); - //QDrag* getTextDrag(QWidget* parent); - QMimeData* getTextDrag(); - void pasteAt(const QString& pt, int pos); void viewDropEvent(QDropEvent* event); virtual void modifySelected(NoteInfo::ValType, int) {} virtual void keyPress(QKeyEvent*); diff --git a/muse2/muse/midiedit/pianoroll.cpp b/muse2/muse/midiedit/pianoroll.cpp index ab83e85f..b2fe55ee 100644 --- a/muse2/muse/midiedit/pianoroll.cpp +++ b/muse2/muse/midiedit/pianoroll.cpp @@ -605,6 +605,15 @@ void PianoRoll::cmd(int cmd) { switch (cmd) { + case PianoCanvas::CMD_CUT: + copy_notes(partlist_to_set(parts()), 1); + erase_notes(partlist_to_set(parts()), 1); + break; + case PianoCanvas::CMD_COPY: copy_notes(partlist_to_set(parts()), 1); break; + case PianoCanvas::CMD_PASTE: + ((PianoCanvas*)canvas)->cmd(PianoCanvas::CMD_SELECT_NONE); + paste_notes(canvas->part()); + break; case PianoCanvas::CMD_MODIFY_GATE_TIME: modify_notelen(partlist_to_set(parts())); break; case PianoCanvas::CMD_MODIFY_VELOCITY: modify_velocity(partlist_to_set(parts())); break; case PianoCanvas::CMD_CRESCENDO: crescendo(partlist_to_set(parts())); break; diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index 75ad3c06..4e81b2e9 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -36,6 +36,7 @@ #include "cmd.h" #include "song.h" #include "audio.h" +#include "functions.h" //--------------------------------------------------------- // NEvent @@ -895,26 +896,6 @@ void PianoCanvas::drawCanvas(QPainter& p, const QRect& rect) void PianoCanvas::cmd(int cmd) { switch (cmd) { - case CMD_CUT: - copy(); - song->startUndo(); - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!(i->second->isSelected())) - continue; - NEvent* e = (NEvent*)(i->second); - Event ev = e->event(); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, e->part(), false); - audio->msgDeleteEvent(ev, e->part(), false, false, false); - } - song->endUndo(SC_EVENT_REMOVED); - break; - case CMD_COPY: - copy(); - break; - case CMD_PASTE: - paste(); - break; case CMD_SELECT_ALL: // select all for (iCItem k = items.begin(); k != items.end(); ++k) { if (!k->second->isSelected()) @@ -1057,181 +1038,13 @@ void PianoCanvas::midiNote(int pitch, int velo) } -/* -//--------------------------------------------------------- -// getTextDrag -//--------------------------------------------------------- - -Q3TextDrag* PianoCanvas::getTextDrag(QWidget* parent) - { - //--------------------------------------------------- - // generate event list from selected events - //--------------------------------------------------- - - EventList el; - unsigned startTick = MAXINT; - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - NEvent* ne = (NEvent*)(i->second); - Event e = ne->event(); - if (startTick == MAXINT) - startTick = e.tick(); - el.add(e); - } - - //--------------------------------------------------- - // write events as XML into tmp file - //--------------------------------------------------- - - FILE* tmp = tmpfile(); - if (tmp == 0) { - fprintf(stderr, "PianoCanvas::copy() fopen failed: %s\n", - strerror(errno)); - return 0; - } - Xml xml(tmp); - - int level = 0; - xml.tag(level++, "eventlist"); - for (ciEvent e = el.begin(); e != el.end(); ++e) - e->second.write(level, xml, -startTick); - xml.etag(--level, "eventlist"); - - //--------------------------------------------------- - // read tmp file into QTextDrag Object - //--------------------------------------------------- - - fflush(tmp); - struct stat f_stat; - if (fstat(fileno(tmp), &f_stat) == -1) { - fprintf(stderr, "PianoCanvas::copy() fstat failes:<%s>\n", - strerror(errno)); - fclose(tmp); - return 0; - } - int n = f_stat.st_size; - char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, - MAP_PRIVATE, fileno(tmp), 0); - fbuf[n] = 0; - Q3TextDrag* drag = new Q3TextDrag(QString(fbuf), parent); - drag->setSubtype("eventlist"); - munmap(fbuf, n); - fclose(tmp); - return drag; - } -*/ - -//--------------------------------------------------------- -// copy -// cut copy paste -//--------------------------------------------------------- - -void PianoCanvas::copy() - { - //QDrag* drag = getTextDrag(); - QMimeData* drag = getTextDrag(); - - if (drag) - QApplication::clipboard()->setMimeData(drag, QClipboard::Clipboard); - } - -/* -//--------------------------------------------------------- -// pasteAt -//--------------------------------------------------------- - -void PianoCanvas::pasteAt(const QString& pt, int pos) - { - QByteArray ba = pt.toLatin1(); - const char* p = ba.constData(); - Xml xml(p); - for (;;) { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - return; - case Xml::TagStart: - if (tag == "eventlist") { - song->startUndo(); - EventList* el = new EventList(); - el->read(xml, "eventlist", true); - int modified = SC_EVENT_INSERTED; - for (iEvent i = el->begin(); i != el->end(); ++i) { - Event e = i->second; - int tick = e.tick() + pos - curPart->tick(); - if (tick<0) { - printf("ERROR: trying to add event before current part!\n"); - song->endUndo(SC_EVENT_INSERTED); - delete el; - return; - } - - e.setTick(tick); - int diff = e.endTick()-curPart->lenTick(); - if (diff > 0) {// too short part? extend it - Part* newPart = curPart->clone(); - newPart->setLenTick(newPart->lenTick()+diff); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(curPart, newPart, false, true, false); - modified=modified|SC_PART_MODIFIED; - curPart = newPart; // reassign - } - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(e, curPart, false, false, false); - } - song->endUndo(modified); - delete el; - return; - } - else - xml.unknown("pasteAt"); - break; - case Xml::Attribut: - case Xml::TagEnd: - default: - break; - } - } - } -*/ - -//--------------------------------------------------------- -// paste -// paste events -//--------------------------------------------------------- - -void PianoCanvas::paste() - { -/* - //Q3CString subtype("eventlist"); ddskrjo - QString subtype("eventlist"); - QMimeSource* ms = QApplication::clipboard()->data(QClipboard::Clipboard); - QString pt; - if (!Q3TextDrag::decode(ms, pt, subtype)) { - printf("cannot paste: bad data type\n"); - return; - } - pasteAt(pt, song->cpos()); -*/ - QString stype("x-muse-eventlist"); - - //QString s = QApplication::clipboard()->text(stype, QClipboard::Selection); - QString s = QApplication::clipboard()->text(stype, QClipboard::Clipboard); // TODO CHECK Tim. - - pasteAt(s, song->cpos()); - } - //--------------------------------------------------------- // startDrag //--------------------------------------------------------- void PianoCanvas::startDrag(CItem* /* item*/, bool copymode) { - QMimeData* md = getTextDrag(); - //QDrag* drag = getTextDrag(); + QMimeData* md = selected_events_to_mime(partlist_to_set(editor->parts()), 1); if (md) { // QApplication::clipboard()->setData(drag, QClipboard::Clipboard); // This line NOT enabled in muse-1 @@ -1281,41 +1094,6 @@ void PianoCanvas::dragLeaveEvent(QDragLeaveEvent*) //event->acceptProposedAction(); } -/* -//--------------------------------------------------------- -// dropEvent -//--------------------------------------------------------- - -void PianoCanvas::viewDropEvent(QDropEvent* event) - { - QString text; - if (event->source() == this) { - printf("local DROP\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - return; - } - ///if (Q3TextDrag::decode(event, text)) { - //if (event->mimeData()->hasText()) { - if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { - - //text = event->mimeData()->text(); - text = QString(event->mimeData()->data("text/x-muse-eventlist")); - - int x = editor->rasterVal(event->pos().x()); - if (x < 0) - x = 0; - pasteAt(text, x); - //event->accept(); // TODO - } - else { - printf("cannot decode drop\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - } - } -*/ - //--------------------------------------------------------- // itemPressed //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/prcanvas.h b/muse2/muse/midiedit/prcanvas.h index b9da00c6..96b5b4f5 100644 --- a/muse2/muse/midiedit/prcanvas.h +++ b/muse2/muse/midiedit/prcanvas.h @@ -69,8 +69,6 @@ class PianoCanvas : public EventCanvas { int y2pitch(int) const; int pitch2y(int) const; virtual void drawCanvas(QPainter&, const QRect&); - void copy(); - void paste(); virtual void itemPressed(const CItem*); virtual void itemReleased(const CItem*, const QPoint&); virtual void itemMoved(const CItem*, const QPoint&); diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index c2e901ad..e0fe6491 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4375,12 +4375,13 @@ void staff_t::update_part_indices() * between, for example, when a cis is tied to a des * * CURRENT TODO - * o investigate with valgrind - * ! o paste to different tick !! + * o when pasting, the pasted, not the previously selected should be selected * o allow batch-movements in score editor + * o in main win: make "Ch" column editable with a line edit + * o either remove these "hidden notes", or deal with them in the score editor + * o investigate with valgrind * o controller view in score editor * o deal with expanding parts - * o in main win: make "Ch" column editable with a line edit * o fix sigedit boxes * o mid-click in pianoroll: change to "delete", or initiate drag and drop between windows? * -- cgit v1.2.3