From: werner s. <wsc...@us...> - 2004-09-29 17:53:12
|
Update of /cvsroot/lmuse/muse/muse In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21746 Modified Files: audio.cpp ctrl.cpp ctrl.h midi.cpp midictrl.cpp mididev.cpp mididev.h midiport.cpp part.cpp part.h song.cpp songfile.cpp undo.cpp Log Message: more fixes to controller handling Index: undo.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/undo.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** undo.cpp 28 Sep 2004 18:32:21 -0000 1.19 --- undo.cpp 29 Sep 2004 17:52:59 -0000 1.20 *************** *** 25,30 **** "AddPart", "DeletePart", "ModifyPart", "AddEvent", "DeleteEvent", "ModifyEvent", ! "AddTempo", "DeleteTempo", "AddSig", ! "SwapTrack" }; return name[type]; --- 25,32 ---- "AddPart", "DeletePart", "ModifyPart", "AddEvent", "DeleteEvent", "ModifyEvent", ! "AddTempo", "DeleteTempo", ! "AddSig", ! "SwapTrack", ! "AddCtrl", "RemoveCtrl", "ModifyCtrl" }; return name[type]; *************** *** 101,105 **** --- 103,110 ---- { Undo& u = undoList->back(); + + // printf("doUndo2\n"); for (riUndoOp i = u.rbegin(); i != u.rend(); ++i) { + // printf(" doUndo2 %s\n", i->typeName()); switch(i->type) { case UndoOp::AddTrack: *************** *** 346,356 **** } ! void Song::undoOp(UndoOp::UndoType type, Track* t, int id, unsigned time, ! float nval, float oval) { UndoOp i; i.type = type; i.track = t; ! i.a = id; i.time = time; i.val1 = nval; --- 351,360 ---- } ! void Song::undoOp(UndoOp::UndoType type, Track* t, int id, unsigned time, float nval, float oval) { UndoOp i; i.type = type; i.track = t; ! i.id = id; i.time = time; i.val1 = nval; *************** *** 392,398 **** insertTrack1(i->oTrack, i->trackno); break; - case UndoOp::AddCtrl: - case UndoOp::RemoveCtrl: - break; default: break; --- 396,399 ---- *************** *** 428,431 **** --- 429,433 ---- case UndoOp::AddCtrl: case UndoOp::RemoveCtrl: + i->track->emitControllerChanged(i->id); break; default: Index: midictrl.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/midictrl.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** midictrl.cpp 26 Sep 2004 20:42:37 -0000 1.24 --- midictrl.cpp 29 Sep 2004 17:52:59 -0000 1.25 *************** *** 68,71 **** --- 68,74 ---- static MidiController volumeCtrl("MainVolume", CTRL_VOLUME, 0, 127, 100); static MidiController panCtrl("Pan", CTRL_PANPOT, 0, 127, 64); + static MidiController reverbCtrl("ReverbSend", CTRL_REVERB_SEND, 0, 127, 0); + static MidiController chorusCtrl("ChorusSend", CTRL_CHORUS_SEND, 0, 127, 0); + static MidiController variationCtrl("VariationSend", CTRL_VARIATION_SEND,0, 127, 0); //--------------------------------------------------------- *************** *** 124,127 **** --- 127,133 ---- void initMidiController() { + static bool initialized = false; + if (initialized) + return; defaultMidiController.push_back(&veloCtrl); defaultMidiController.push_back(&pitchCtrl); *************** *** 130,133 **** --- 136,143 ---- defaultMidiController.push_back(&volumeCtrl); defaultMidiController.push_back(&panCtrl); + defaultMidiController.push_back(&reverbCtrl); + defaultMidiController.push_back(&chorusCtrl); + defaultMidiController.push_back(&variationCtrl); + initialized = true; } *************** *** 235,242 **** { ControllerType t = Controller7; - _initVal = CTRL_VAL_UNKNOWN; static const int NOT_SET = 0x100000; - // _minVal = NOT_SET; - // _maxVal = NOT_SET; int l = 0; --- 245,249 ---- *************** *** 249,256 **** l = 0xff; else ! l = s.toInt(0,0); ! _minVal = e.attribute("min", "0x100000").toInt(0,0); ! _maxVal = e.attribute("max", "0x100000").toInt(0,0); ! _initVal = e.attribute("init", "0x10000000").toInt(0,0); _num = (h << 8) + l; --- 256,263 ---- l = 0xff; else ! l = s.toInt(0,0); ! _minVal = e.attribute("min", "0").toInt(0,0); ! _maxVal = e.attribute("max", "0x100000").toInt(0,0); ! _initVal = e.attribute("init", "-1").toInt(0,0); _num = (h << 8) + l; *************** *** 300,305 **** break; } - if (_minVal == NOT_SET) - _minVal = 0; return; } --- 307,310 ---- Index: ctrl.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/ctrl.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ctrl.cpp 28 Sep 2004 18:32:20 -0000 1.11 --- ctrl.cpp 29 Sep 2004 17:52:59 -0000 1.12 *************** *** 26,30 **** min = 0.0; max = 1.0; ! _changed = true; } --- 26,30 ---- min = 0.0; max = 1.0; ! _changed = false; } *************** *** 41,45 **** min = 0.0; max = 1.0; ! _changed = true; } --- 41,45 ---- min = 0.0; max = 1.0; ! _changed = false; } *************** *** 215,219 **** int Ctrl::val2pixel(float val, int maxpixel) { - float oval = val; if (_type & LOG) { if (val <= 0.0f) --- 215,218 ---- *************** *** 222,229 **** val = fast_log10(val); } ! // return maxpixel - lrint((val * maxpixel) / (max - min) + min); ! int pixel = lrint(float(maxpixel) * (float(val) - min) / (max-min)); ! printf("val2pixel %d(%d) val %f(%f) (%f-%f)\n", pixel, maxpixel, val, oval, min,max); ! return pixel; } --- 221,225 ---- val = fast_log10(val); } ! return lrint(float(maxpixel) * (float(val) - min) / (max-min)); } *************** *** 235,239 **** int Ctrl::val2pixelR(float val, int maxpixel) { ! return maxpixel - lrint(float(maxpixel) * (float(val) - min) / (max-min)); } --- 231,237 ---- int Ctrl::val2pixelR(float val, int maxpixel) { ! int rv = maxpixel - lrint(float(maxpixel) * (float(val) - min) / (max-min)); ! // printf("val2pixelR %d %d(%d) val %f (%f-%f)\n", _id, rv, maxpixel, val, min,max); ! return rv; } *************** *** 250,254 **** else if (rv > max) rv = max; - float ov = rv; if (_type & LOG) rv = pow(10.0f, rv); --- 248,251 ---- Index: mididev.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/mididev.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** mididev.cpp 14 Sep 2004 18:17:23 -0000 1.13 --- mididev.cpp 29 Sep 2004 17:52:59 -0000 1.14 *************** *** 305,315 **** } - //--------------------------------------------------------- - // schedEvent - //--------------------------------------------------------- - - void MidiDevice::schedEvent(const MidiPlayEvent& ev) - { - _playEvents.add(ev); - } - --- 305,306 ---- Index: midiport.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/midiport.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** midiport.cpp 28 Sep 2004 18:32:21 -0000 1.33 --- midiport.cpp 29 Sep 2004 17:52:59 -0000 1.34 *************** *** 39,42 **** --- 39,44 ---- : _state("not configured") { + initMidiController(); + _device = 0; _instrument = 0; *************** *** 76,79 **** --- 78,83 ---- pvl->setRange(float(mc->minVal()), float(mc->maxVal())); } + else + printf("unknown midi controller %x\n", ctrl); pvl->setCurVal(float(CTRL_VAL_UNKNOWN)); pvl->setType(Ctrl::DISCRETE); *************** *** 505,509 **** QString name = midiCtrlName(num); int min = 0; ! int max = 128 * 128 - 1; MidiController* c = new MidiController(name, num, min, max, 0); defaultMidiController.push_back(c); --- 509,513 ---- QString name = midiCtrlName(num); int min = 0; ! int max = 127; MidiController* c = new MidiController(name, num, min, max, 0); defaultMidiController.push_back(c); Index: songfile.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/songfile.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** songfile.cpp 28 Sep 2004 18:32:21 -0000 1.36 --- songfile.cpp 29 Sep 2004 17:52:59 -0000 1.37 *************** *** 287,291 **** } else { - _events->add(e); if (e.type() == Controller) { int port = ((MidiTrack*)_track)->outPort(); --- 287,290 ---- *************** *** 294,297 **** --- 293,298 ---- mp->setCtrl(channel, tick, e.dataA(), e.dataB()); } + else + _events->add(e); } } Index: midi.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/midi.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** midi.cpp 28 Sep 2004 18:32:21 -0000 1.53 --- midi.cpp 29 Sep 2004 17:52:59 -0000 1.54 *************** *** 474,478 **** } ev.setTick(tick); ! del->add(ev); } } --- 474,485 ---- } ev.setTick(tick); ! if (ev.type() == Controller) { ! int port = track->outPort(); ! int channel = track->outChannel(); ! MidiPort* mp = &midiPorts[port]; ! mp->setCtrl(channel, tick, ev.dataA(), ev.dataB()); ! } ! else ! del->add(ev); } } *************** *** 578,673 **** void Audio::collectEvents(MidiTrack* track, unsigned cts, unsigned nts) { PartList* pl = track->parts(); for (iPart p = pl->begin(); p != pl->end(); ++p) { MidiPart* part = (MidiPart*)(p->second); - // dont play muted parts if (part->mute()) continue; ! EventList* events = part->events(); ! unsigned partTick = part->tick(); ! int delay = track->delay; - if (cts > nts) { - printf("processMidi: FATAL: cur > next %d > %d\n", - cts, nts); - return; - } - unsigned offset = delay + partTick; if (offset > nts) ! continue; ! unsigned stick = (offset > cts) ? 0 : cts - offset; ! unsigned etick = nts - offset; ! iEvent ie = events->lower_bound(stick); ! iEvent iend = events->lower_bound(etick); for (; ie != iend; ++ie) { Event ev = ie->second; ! // ! // don´t play any meta events ! // ! if (ev.type() == Meta) continue; - if (track->type() == Track::DRUM) { - int instr = ev.pitch(); - // ignore muted drums - if (ev.isNote() && drumMap[instr].mute) - continue; - } unsigned tick = ev.tick() + offset; unsigned frame = tempomap.tick2frame(tick) + frameOffset; ! int port = track->outPort(); ! int channel = track->outChannel(); ! switch (ev.type()) { ! case Note: ! { ! int len = ev.lenTick(); ! int pitch = ev.pitch(); ! if (track->type() == Track::DRUM) { ! // ! // Map drum-notes to the drum-map values ! // ! int instr = ev.pitch(); ! pitch = drumMap[instr].anote; ! port = drumMap[instr].port; //This changes to non-default port ! channel = drumMap[instr].channel; ! } ! else { ! // ! // transpose non drum notes ! // ! pitch += (track->transposition + song->globalPitchShift()); ! } ! if (pitch > 127) ! pitch = 127; ! if (pitch < 0) ! pitch = 0; ! int velo = ev.velo(); ! velo += track->velocity; ! velo = (velo * track->compression) / 100; ! if (velo > 127) ! velo = 127; ! if (velo < 1) // no off event ! velo = 1; ! len = (len * track->len) / 100; ! if (len <= 0) // don´t allow zero length ! len = 1; ! int veloOff = ev.veloOff(); ! MidiPort& mp = midiPorts[port]; ! MidiDevice* md = mp.device(); ! if (md) { ! md->playEvents()->add(MidiPlayEvent(frame, port, channel, 0x90, pitch, velo)); ! md->stuckNotes()->add(MidiPlayEvent(tick + len, port, channel, ! veloOff ? 0x80 : 0x90, pitch, veloOff)); ! } ! mp.setMeter(channel, mp.meter(channel) + velo); } ! break; ! ! default: ! // optimize controller events ! midiPorts[port].sendEvent(MidiPlayEvent(frame, port, channel, ev)); ! break; } } --- 585,668 ---- void Audio::collectEvents(MidiTrack* track, unsigned cts, unsigned nts) { + if (cts > nts) { + printf("processMidi: FATAL: cur > next %d > %d\n", cts, nts); + return; + } + + int port = track->outPort(); + int channel = track->outChannel(); + MidiPort& mp = midiPorts[port]; + MidiDevice* md = mp.device(); + PartList* pl = track->parts(); for (iPart p = pl->begin(); p != pl->end(); ++p) { MidiPart* part = (MidiPart*)(p->second); if (part->mute()) continue; ! unsigned offset = track->delay + part->tick(); if (offset > nts) ! break; ! ! EventList* events = part->events(); ! ! iEvent ie = events->lower_bound((offset > cts) ? 0 : cts - offset); ! iEvent iend = events->lower_bound(nts - offset); for (; ie != iend; ++ie) { Event ev = ie->second; ! if (ev.type() == Meta) // dont play meta events ! continue; ! // ignore muted drums ! if (track->type() == Track::DRUM ! && ev.isNote() && drumMap[ev.pitch()].mute) continue; unsigned tick = ev.tick() + offset; unsigned frame = tempomap.tick2frame(tick) + frameOffset; ! if (ev.type() == Note) { ! int len = ev.lenTick(); ! int pitch = ev.pitch(); ! if (track->type() == Track::DRUM) { ! // ! // Map drum-notes to the drum-map values ! // ! int instr = ev.pitch(); ! pitch = drumMap[instr].anote; ! port = drumMap[instr].port; //This changes to non-default port ! channel = drumMap[instr].channel; ! } ! else { ! // ! // transpose non drum notes ! // ! pitch += (track->transposition + song->globalPitchShift()); ! } ! if (pitch > 127) ! pitch = 127; ! if (pitch < 0) ! pitch = 0; ! int velo = ev.velo(); ! velo += track->velocity; ! velo = (velo * track->compression) / 100; ! if (velo > 127) ! velo = 127; ! if (velo < 1) // no off event ! velo = 1; ! len = (len * track->len) / 100; ! if (len <= 0) // don´t allow zero length ! len = 1; ! int veloOff = ev.veloOff(); ! if (md) { ! md->schedEvent(MidiPlayEvent(frame, port, channel, 0x90, pitch, velo)); ! md->stuckEvent(MidiPlayEvent(tick + len, port, channel, ! veloOff ? 0x80 : 0x90, pitch, veloOff)); } ! mp.setMeter(channel, mp.meter(channel) + velo); ! } ! else { ! // optimize controller events ! midiPorts[port].sendEvent(MidiPlayEvent(frame, port, channel, ev)); } } *************** *** 713,716 **** --- 708,714 ---- playEvents->erase(playEvents->begin(), nextPlayEvent); + // + // play all events send from GUI + // for (;;) { MidiPlayEvent* ev = audio->getMidiEvent(); *************** *** 723,738 **** for (iMidiTrack t = song->midis()->begin(); t != song->midis()->end(); ++t) { MidiTrack* track = *t; - int port = track->outPort(); - MidiDevice* md = midiPorts[port].device(); if (track->isMute()) continue; - if (isPlaying()) collectEvents(track, curTickPos, nextTickPos); - MPEventList* playEvents = md ? md->playEvents() : 0; // //----------midi recording // if (md && track->recordFlag()) { int portMask = track->inPortMask(); --- 721,733 ---- for (iMidiTrack t = song->midis()->begin(); t != song->midis()->end(); ++t) { MidiTrack* track = *t; if (track->isMute()) continue; if (isPlaying()) collectEvents(track, curTickPos, nextTickPos); // //----------midi recording // + MidiDevice* md = midiPorts[track->outPort()].device(); if (md && track->recordFlag()) { int portMask = track->inPortMask(); *************** *** 756,760 **** MidiPlayEvent event(*ie); int drumRecPitch; //Hmmm, hehhh... TODO: Clean up a bit around here when it comes to separate events for rec & for playback. But not before 0.7 (ml) ! int prePitch = 0, preVelo = 0; event.setChannel(track->outChannel()); --- 751,756 ---- MidiPlayEvent event(*ie); int drumRecPitch; //Hmmm, hehhh... TODO: Clean up a bit around here when it comes to separate events for rec & for playback. But not before 0.7 (ml) ! int prePitch = 0; ! int preVelo = 0; event.setChannel(track->outChannel()); *************** *** 864,867 **** --- 860,887 ---- } stuckNotes->erase(stuckNotes->begin(), k); + + // collect controller + if (isPlaying()) { + int port = md->midiPort(); + if (port != -1) { + MidiPort* mp = &midiPorts[port]; + for (int i = 0; i < MIDI_CHANNELS; ++i) { + CtrlList* cl = mp->controller(i); + for (iCtrl ic = cl->begin(); ic != cl->end(); ++ic) { + Ctrl* c = ic->second; + iCtrlVal is = c->lower_bound(curTickPos); + iCtrlVal ie = c->lower_bound(nextTickPos); + for (iCtrlVal ic = is; ic != ie; ++ic) { + unsigned frame = tempomap.tick2frame(ic->first) + frameOffset; + Event ev(Controller); + ev.setA(c->id()); + ev.setB(int(ic->second)); + mp->sendEvent(MidiPlayEvent(frame, port, i, ev)); + } + } + } + } + } + md->setNextPlayEvent(playEvents->begin()); } Index: part.h =================================================================== RCS file: /cvsroot/lmuse/muse/muse/part.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** part.h 19 Sep 2004 10:53:34 -0000 1.10 --- part.h 29 Sep 2004 17:52:59 -0000 1.11 *************** *** 108,115 **** //--------------------------------------------------------- ! typedef std::multimap<int, Part*, std::less<unsigned> >::iterator iPart; ! typedef std::multimap<int, Part*, std::less<unsigned> >::const_iterator ciPart; ! class PartList : public std::multimap<int, Part*, std::less<unsigned> > { public: iPart findPart(unsigned tick); --- 108,116 ---- //--------------------------------------------------------- ! typedef std::multimap<unsigned, Part*, std::less<unsigned> > PL; ! typedef PL::iterator iPart; ! typedef PL::const_iterator ciPart; ! class PartList : public PL { public: iPart findPart(unsigned tick); Index: song.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/song.cpp,v retrieving revision 1.83 retrieving revision 1.84 diff -C2 -d -r1.83 -r1.84 *** song.cpp 28 Sep 2004 18:32:21 -0000 1.83 --- song.cpp 29 Sep 2004 17:52:59 -0000 1.84 *************** *** 1170,1179 **** void Song::endMsgCmd() { ! if (updateFlags) { redoList->clear(); // TODO: delete elements in list undoAction->setEnabled(true); redoAction->setEnabled(false); ! emit songChanged(updateFlags); ! } } --- 1170,1180 ---- void Song::endMsgCmd() { ! // if (updateFlags) { redoList->clear(); // TODO: delete elements in list undoAction->setEnabled(true); redoAction->setEnabled(false); ! if (updateFlags) ! emit songChanged(updateFlags); ! // } } Index: part.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/part.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** part.cpp 19 Sep 2004 16:12:11 -0000 1.16 --- part.cpp 29 Sep 2004 17:52:59 -0000 1.17 *************** *** 131,135 **** iPart PartList::add(Part* part) { ! return insert(std::pair<const int, Part*> (part->tick(), part)); } --- 131,135 ---- iPart PartList::add(Part* part) { ! return insert(std::pair<const unsigned, Part*> (part->tick(), part)); } Index: mididev.h =================================================================== RCS file: /cvsroot/lmuse/muse/muse/mididev.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** mididev.h 14 Sep 2004 18:17:23 -0000 1.6 --- mididev.h 29 Sep 2004 17:52:59 -0000 1.7 *************** *** 59,63 **** void recordEvent(MidiRecordEvent&); bool putEvent(const MidiPlayEvent&); ! void schedEvent(const MidiPlayEvent& ev); MPEventList* stuckNotes() { return &_stuckNotes; } --- 59,64 ---- void recordEvent(MidiRecordEvent&); bool putEvent(const MidiPlayEvent&); ! void schedEvent(const MidiPlayEvent& ev) { _playEvents.add(ev); } ! void stuckEvent(const MidiPlayEvent& ev) { _stuckNotes.add(ev); } MPEventList* stuckNotes() { return &_stuckNotes; } Index: ctrl.h =================================================================== RCS file: /cvsroot/lmuse/muse/muse/ctrl.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ctrl.h 28 Sep 2004 18:32:21 -0000 1.11 --- ctrl.h 29 Sep 2004 17:52:59 -0000 1.12 *************** *** 133,137 **** //--------------------------------------------------------- ! typedef std::map<int, Ctrl*, std::less<int> > CLIST; typedef CLIST::iterator iCtrl; typedef CLIST::const_iterator ciCtrl; --- 133,137 ---- //--------------------------------------------------------- ! typedef std::map<unsigned, Ctrl*, std::less<unsigned> > CLIST; typedef CLIST::iterator iCtrl; typedef CLIST::const_iterator ciCtrl; Index: audio.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/audio.cpp,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** audio.cpp 28 Sep 2004 18:32:20 -0000 1.74 --- audio.cpp 29 Sep 2004 17:52:59 -0000 1.75 *************** *** 36,40 **** "SEQM_ADD_PART", "SEQM_REMOVE_PART", "SEQM_CHANGE_PART", "SEQM_ADD_EVENT", "SEQM_REMOVE_EVENT", "SEQM_CHANGE_EVENT", ! "SEQM_ADD_TEMPO", "SEQM_SET_TEMPO", "SEQM_REMOVE_TEMPO", "SEQM_ADD_SIG", "SEQM_SET_GLOBAL_TEMPO", --- 36,40 ---- "SEQM_ADD_PART", "SEQM_REMOVE_PART", "SEQM_CHANGE_PART", "SEQM_ADD_EVENT", "SEQM_REMOVE_EVENT", "SEQM_CHANGE_EVENT", ! "SEQM_ADD_TEMPO", "SEQM_SET_TEMPO", "SEQM_REMOVE_TEMPO", "SEQM_ADD_SIG", "SEQM_SET_GLOBAL_TEMPO", |