-------------- void Song::process_crop(JmbMessage* m, bool type) { if (m->beginHold) { MustuxAction* a = new MustuxCropAction(this,m); return a; } else { MustuxAction* a = MHE->current(); a->do(); return (MustuxAction*) 0; // this is to avoid another PUSH ! MHE must be prepared to ignore pushing zeros... } PEXIT; } class MustuxCropAction : public MustuxAction { public : MustuxCropAction(Song* mySong, JmbMessage* m) : MustuxAction(m) { this->mySong = mySong; this->origBlockL = mySong->xpos_to_block(mySong->clip_area_mouse_x(jmbMessage->mousex())); this->origBlockR = -1; mySong->update_last_block(); QPtrList originalCliplist = new QPtrList() QPtrList clipToDeletelist = new QPtrList() } void do_action() { this->origBlockR = mySong->xpos_to_block(mySong->clip_area_mouse_x(jmbMessage->mousex())); // save the original clipsclips for (int t =0; tnumTracks; t++) { AudioClip* cli1 = mySong->track[t]->get_clip_under(origBlockL); AudioClip* cli2 = mySong->track[t]->get_clip_under(origBlockR); originalCliplist->add(cli1); originalCliplist->add(cli1); } PMESG2("Splitting clips at %ld and %ld",(long)origBlockL,(long)origBlockR); for (int t =0; tnumTracks; t++) { // ClipPair is a auxiliary class returned by split so you have pointer to the two remaining clips after split. in this example, I assume it exists, but must still be implemented... ClipPair* cpLeft = mySong->track[t]->split_clip(origBlockL); ClipPair* cpRight = mySong->track[t]->split_clip(origBlockR); // save them for deletion in case of undo clipToDeleteList->add(cpLeft->clipAtLeft); clipToDeleteList->add(cpLeft->clipAtRight); clipToDeleteList->add(cpRight->clipAtLeft); clipToDeleteList->add(cpRight->clipAtRight); } long long hb = (origBlockL+origBlockR)/2; PMESG2("Deleting all clips in the half point (%ld)",(long)hb); for (int t =0; tnumTracks; t++) { AudioClip* cli = mySong->track[t]->get_clip_under(hb); if (cli) mySong->track[t]->delete_clip(cli); // thats why I need it ! } long long mb = origBlockR - origBlockL; PMESG2("Moving all clips beyond %ld and moving left in %ld blocks\n",(long)origBlockL,(long)mb); for (int t =0; tnumTracks; t++) { AudioClip* cli = mySong->track[t]->get_clip_after(origBlockL); while (cli) { long long tfb = cli->trackFirstBlock; cli->set_track_first_block(tfb - mb); cli=cli->next; } } mySong->mta->recreate(); mySong->update_last_block(); } void undo_action() { // delete the created clips QPtrListITerator it(clipToDeleteList); { for ( it; it.hasNext(); ++it) { AudioClip* c= it.get(); delete c; } } // RESTORE THE ORIGINAL CLIPS QPtrListITerator it(originalClipList); { for ( it; it.hasNext(); ++it) { AudioClip* c= it.get(); c->reparent(); // that method does not exist. must be implemented. it just ask the parent track to re-add it. } } } }