summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2011-07-03 15:53:46 +0000
committerFlorian Jung <flo@windfisch.org>2011-07-03 15:53:46 +0000
commit3970fed7542ca0377c7f418f86f93c513c9b0b63 (patch)
tree6eb725374766461613f72f0a26cd163512c39749
parent99934de53a85e71c8a33c1f39f16eb46d2df3cb7 (diff)
auto-expanding for the score edit's resize tool and for the
global "move notes" function
-rw-r--r--muse2/muse/functions.cpp25
-rw-r--r--muse2/muse/midiedit/scoreedit.cpp56
-rw-r--r--muse2/muse/midiedit/scoreedit.h4
3 files changed, 53 insertions, 32 deletions
diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp
index 9ab209c6..e34adb11 100644
--- a/muse2/muse/functions.cpp
+++ b/muse2/muse/functions.cpp
@@ -286,7 +286,7 @@ bool modify_off_velocity(const set<Part*>& parts, int range, int rate, int offse
return false;
}
-bool modify_notelen(const set<Part*>& parts, int range, int rate, int offset)
+bool modify_notelen(const set<Part*>& parts, int range, int rate, int offset) //FINDMICH EXTEND
{
map<Event*, Part*> events = get_events(parts, range);
Undo operations;
@@ -320,7 +320,7 @@ bool modify_notelen(const set<Part*>& parts, int range, int rate, int offset)
return false;
}
-bool set_notelen(const set<Part*>& parts, int range, int len)
+bool set_notelen(const set<Part*>& parts, int range, int len) //FINDMICH EXTEND
{
return modify_notelen(parts, range, 0, len);
}
@@ -481,10 +481,11 @@ bool crescendo(const set<Part*>& parts, int range, int start_val, int end_val, b
return false;
}
-bool move_notes(const set<Part*>& parts, int range, signed int ticks) //TODO: clipping
+bool move_notes(const set<Part*>& parts, int range, signed int ticks)
{
map<Event*, Part*> events = get_events(parts, range);
Undo operations;
+ map<Part*, int> partlen;
if ( (!events.empty()) && (ticks!=0) )
{
@@ -500,12 +501,17 @@ bool move_notes(const set<Part*>& parts, int range, signed int ticks) //TODO: cl
else
newEvent.setTick(event.tick()+ticks);
- if (newEvent.endTick() > part->lenTick()) //if exceeding the part's end, clip
+ if (newEvent.endTick() > part->lenTick()) //if exceeding the part's end:
{
- if (part->lenTick() > newEvent.tick())
- newEvent.setLenTick(part->lenTick() - newEvent.tick());
+ if (part->hasHiddenNotes()) // auto-expanding is forbidden, clip
+ {
+ if (part->lenTick() > newEvent.tick())
+ newEvent.setLenTick(part->lenTick() - newEvent.tick());
+ else
+ del=true; //if the new length would be <= 0, erase the note
+ }
else
- del=true; //if the new length would be <= 0, erase the note
+ partlen[part]=newEvent.endTick(); // schedule auto-expanding
}
if (del==false)
@@ -514,6 +520,9 @@ bool move_notes(const set<Part*>& parts, int range, signed int ticks) //TODO: cl
operations.push_back(UndoOp(UndoOp::DeleteEvent, event, part, false, false));
}
+ for (map<Part*, int>::iterator it=partlen.begin(); it!=partlen.end(); it++)
+ schedule_resize_all_same_len_clone_parts(it->first, it->second, operations);
+
return song->applyOperationGroup(operations);
}
else
@@ -712,7 +721,7 @@ QMimeData* selected_events_to_mime(const set<Part*>& parts, int range)
return md;
}
-void paste_at(Part* dest_part, const QString& pt, int pos)
+void paste_at(Part* dest_part, const QString& pt, int pos) //FINDMICH EXTEND
{
Undo operations;
diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp
index 0cb5428f..f50af815 100644
--- a/muse2/muse/midiedit/scoreedit.cpp
+++ b/muse2/muse/midiedit/scoreedit.cpp
@@ -1189,6 +1189,7 @@ ScoreCanvas::ScoreCanvas(ScoreEdit* pr, QWidget* parent_widget) : View(parent_wi
undo_started=false;
selected_part=NULL;
+ dragged_event_part=NULL;
last_len=384;
new_len=-1;
@@ -3624,7 +3625,7 @@ void ScoreCanvas::mousePressEvent (QMouseEvent* event)
clicked_event_ptr=set_it->source_event;
dragged_event=*set_it->source_event;
original_dragged_event=dragged_event.clone();
- dragged_event_part=set_it->source_part;
+ set_dragged_event_part(set_it->source_part);
if ((mouse_erases_notes) || (event->button()==Qt::MidButton)) //erase?
{
@@ -3665,7 +3666,6 @@ void ScoreCanvas::mousePressEvent (QMouseEvent* event)
signed int relative_tick=(signed) tick - curr_part->tick();
if (relative_tick<0)
cerr << "ERROR: THIS SHOULD NEVER HAPPEN: relative_tick is negative!" << endl;
- song->startUndo();
if (!ctrl)
deselect_all();
@@ -3685,13 +3685,13 @@ void ScoreCanvas::mousePressEvent (QMouseEvent* event)
" setting it to " << newevent.lenTick() << endl;
}
- if (newevent.endTick() > curr_part->lenTick()) //FINDMICH EXTEND
+ if (newevent.endTick() > curr_part->lenTick())
{
if (debugMsg) cout << "clipping inserted note from len="<<newevent.endTick()<<" to len="<<(curr_part->lenTick() - newevent.tick())<<endl;
newevent.setLenTick(curr_part->lenTick() - newevent.tick());
}
- audio->msgAddEvent(newevent, curr_part, false, false, false);
+ audio->msgAddEvent(newevent, curr_part, true, false, false);
dragged_event_part=curr_part;
dragged_event=newevent;
@@ -3709,7 +3709,6 @@ void ScoreCanvas::mousePressEvent (QMouseEvent* event)
drag_cursor_changed=true;
setCursor(Qt::SizeAllCursor);
- song->endUndo(SC_EVENT_INSERTED);
song->update(SC_SELECTION);
}
}
@@ -3738,15 +3737,13 @@ void ScoreCanvas::mouseReleaseEvent (QMouseEvent* event)
if (flo_quantize(dragged_event.lenTick(), quant_ticks()) <= 0)
{
if (debugMsg) cout << "new length <= 0, erasing item" << endl;
- audio->msgDeleteEvent(dragged_event, dragged_event_part, false, false, false);
+ if (undo_started) song->undo();
+ audio->msgDeleteEvent(dragged_event, dragged_event_part, true, false, false);
}
else
{
last_len=flo_quantize(dragged_event.lenTick(), quant_ticks());
}
-
- if (undo_started)
- song->endUndo(SC_EVENT_MODIFIED | SC_EVENT_REMOVED);
}
@@ -3864,6 +3861,7 @@ void ScoreCanvas::mouseMoveEvent (QMouseEvent* event)
old_pitch=-1;
old_dest_tick=MAXINT;
+ old_len=-1;
}
}
@@ -3906,7 +3904,7 @@ void ScoreCanvas::mouseMoveEvent (QMouseEvent* event)
if (dest_tick != old_dest_tick)
{
- if (undo_started) song->undo();
+ if (undo_started) song->undo(); //FINDMICH EXTEND
undo_started=move_notes(part_to_set(dragged_event_part),1, (signed)dest_tick-original_dragged_event.tick());
old_dest_tick=dest_tick;
}
@@ -3916,14 +3914,8 @@ void ScoreCanvas::mouseMoveEvent (QMouseEvent* event)
case LENGTH:
tick+=quant_ticks();
- if (dragged_event.tick()+dragged_event.lenTick() + dragged_event_part->tick() != unsigned(tick))
+ if (dragged_event.tick()+old_len + dragged_event_part->tick() != unsigned(tick))
{
- if (!undo_started)
- {
- song->startUndo();
- undo_started=true;
- }
-
Event tmp=dragged_event.clone();
signed relative_tick=tick-signed(dragged_event_part->tick());
signed new_len=relative_tick-dragged_event.tick();
@@ -3936,16 +3928,29 @@ void ScoreCanvas::mouseMoveEvent (QMouseEvent* event)
if (debugMsg) cout << "not setting len to a negative value. using 0 instead" << endl;
}
- if (tmp.endTick() > dragged_event_part->lenTick()) //FINDMICH EXTEND
+ unsigned newpartlen=dragged_event_part->lenTick();
+ if (tmp.endTick() > dragged_event_part->lenTick())
{
- tmp.setLenTick(dragged_event_part->lenTick() - tmp.tick());
- if (debugMsg) cout << "resized note would exceed its part; limiting length to " << tmp.lenTick() << endl;
+ if (dragged_event_part->hasHiddenNotes()) // do not allow autoexpand
+ {
+ tmp.setLenTick(dragged_event_part->lenTick() - tmp.tick());
+ if (debugMsg) cout << "resized note would exceed its part; limiting length to " << tmp.lenTick() << endl;
+ }
+ else
+ {
+ newpartlen=tmp.endTick();
+ if (debugMsg) cout << "resized note would exceeds its part; expanding the part..." << endl;
+ }
}
- audio->msgChangeEvent(dragged_event, tmp, dragged_event_part, false, false, false);
- dragged_event=tmp;
+ if (undo_started) song->undo();
+ Undo operations;
+ operations.push_back(UndoOp(UndoOp::ModifyEvent, tmp, dragged_event, dragged_event_part, false, false));
+ if (newpartlen != dragged_event_part->lenTick())
+ schedule_resize_all_same_len_clone_parts(dragged_event_part, newpartlen, operations);
+ undo_started=song->applyOperationGroup(operations);
- fully_recalculate();
+ old_len=new_len;
}
break;
@@ -4414,6 +4419,9 @@ void ScoreCanvas::update_parts()
if (selected_part!=NULL) //if it's null, let it be null
selected_part=partFromSerialNumber(selected_part_index);
+ if (dragged_event_part!=NULL) //same thing here
+ dragged_event_part=partFromSerialNumber(dragged_event_part_index);
+
for (list<staff_t>::iterator it=staves.begin(); it!=staves.end(); it++)
it->update_parts();
}
@@ -4457,7 +4465,7 @@ void staff_t::update_part_indices()
* between, for example, when a cis is tied to a des
*
* CURRENT TODO
- * o do autoexpand in scoreedit.cpp
+ * o do autoexpand in scoreedit.cpp and functions.cpp
* o draw the edge of parts hiding notes "jagged" (hasHiddenNotes() is interesting for this)
*
* IMPORTANT TODO
diff --git a/muse2/muse/midiedit/scoreedit.h b/muse2/muse/midiedit/scoreedit.h
index e7302a46..6a5dd63a 100644
--- a/muse2/muse/midiedit/scoreedit.h
+++ b/muse2/muse/midiedit/scoreedit.h
@@ -701,12 +701,14 @@ class ScoreCanvas : public View
bool dragging;
bool drag_cursor_changed;
Part* dragged_event_part;
+ int dragged_event_part_index;
Event dragged_event;
Event original_dragged_event;
Event* clicked_event_ptr;
int old_pitch;
unsigned old_dest_tick;
+ int old_len;
bool have_lasso;
QPoint lasso_start;
@@ -811,6 +813,8 @@ class ScoreCanvas : public View
Part* get_selected_part() {return selected_part;}
void set_selected_part(Part* p) {selected_part=p; if (selected_part) selected_part_index=selected_part->sn();}
+ Part* get_dragged_event_part() {return dragged_event_part;}
+ void set_dragged_event_part(Part* p) {dragged_event_part=p; if (dragged_event_part) dragged_event_part_index=dragged_event_part->sn();}
set<Part*> get_all_parts();