void ME_CCEventAtEditCursor (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd) { BR_MouseInfo mouseInfo(BR_MouseInfo::MODE_MIDI_EDITOR_ALL); if (mouseInfo.GetMidiEditor()) { if (MediaItem_Take* take = MIDIEditor_GetTake(mouseInfo.GetMidiEditor())) { double positionPPQ = MIDI_GetPPQPosFromProjTime(take, GetCursorPositionEx(NULL)); int lane, value; if (mouseInfo.GetCCLane(&lane, &value, NULL) && value >= 0) { if (lane == CC_TEXT_EVENTS || lane == CC_SYSEX || lane == CC_BANK_SELECT || lane == CC_VELOCITY) MessageBox((HWND)mouseInfo.GetMidiEditor(), __LOCALIZE("Can't insert in velocity, text, sysex and bank select lanes","sws_mbox"), __LOCALIZE("SWS/BR - Warning","sws_mbox"), MB_OK); else { bool do14bit = (lane >= CC_14BIT_START) ? true : false; int type = (lane == CC_PROGRAM) ? (STATUS_PROGRAM) : (lane == CC_CHANNEL_PRESSURE ? STATUS_CHANNEL_PRESSURE : (lane == CC_PITCH ? STATUS_PITCH : STATUS_CC)); int channel = MIDIEditor_GetSetting_int(mouseInfo.GetMidiEditor(), "default_note_chan"); int msg2 = CheckBounds(lane, 0, 127) ? ((value >> 7) | 0) : (value & 0x7F); int msg3 = CheckBounds(lane, 0, 127) ? (value & 0x7F) : ((value >> 7) | 0); int targetLane = (do14bit) ? lane - CC_14BIT_START : lane; int targetLane2 = (do14bit) ? targetLane + 32 : lane; MIDI_InsertCC(take, true, false, positionPPQ, type, channel, (CheckBounds(targetLane, 0, 127) ? targetLane : msg2), msg3); if (do14bit) MIDI_InsertCC(take, true, false, positionPPQ, type, channel, targetLane2, msg2); Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ITEMS, -1); } } } }
bool replaceCCLanes(const char* _newCClanes) { bool updated = false; HWND me = MIDIEditor_GetActive(); MediaItem_Take* tk = me ? MIDIEditor_GetTake(me) : NULL; if (tk) { MediaItem* item = GetMediaItemTake_Item(tk); int tkIdx = GetTakeIndex(item, tk); // NULL item managed if (tkIdx >= 0) { SNM_TakeParserPatcher p(item, CountTakes(item)); WDL_FastString takeChunk; int tkPos, tklen; if (p.GetTakeChunk(tkIdx, &takeChunk, &tkPos, &tklen)) { SNM_ChunkParserPatcher ptk(&takeChunk, false); int pos = ptk.Parse(SNM_GET_CHUNK_CHAR, 1, "SOURCE", "VELLANE", 0, 0); if (pos > 0) { pos--; // see SNM_ChunkParserPatcher // Remove all lanes for this take if (ptk.RemoveLines("VELLANE")) { ptk.GetChunk()->Insert(_newCClanes, pos); // default lane (min sized) updated = p.ReplaceTake(tkPos, tklen, ptk.GetChunk()); } } } } } return updated; }
void MainSetCCLanes(COMMAND_T* _ct) { HWND me = MIDIEditor_GetActive(); MediaItem_Take* tk = me ? MIDIEditor_GetTake(me) : NULL; if (tk) { // recall lanes char laneSlot[SNM_MAX_CC_LANES_LEN], slot[32] = ""; if (_snprintfStrict(slot, sizeof(slot), "cc_lanes_slot%d", (int)_ct->user + 1) > 0) { GetPrivateProfileString("MidiEditor", slot, "", laneSlot, SNM_MAX_CC_LANES_LEN, g_SNM_IniFn.Get()); int i=0; while (laneSlot[i] && i < (SNM_MAX_CC_LANES_LEN-2)) // -2: see string termination { if (laneSlot[i] == '|') laneSlot[i] = '\n'; i++; } laneSlot[i++] = '\n'; laneSlot[i] = 0; if (replaceCCLanes(laneSlot)) Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(_ct), UNDO_STATE_ALL, -1); } } }
void ME_ShowUsedCCLanesDetect14Bit (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd) { if (MediaItem_Take* take = MIDIEditor_GetTake(MIDIEditor_GetActive())) { RprTake rprTake(take); if (RprMidiCCLane* laneView = new (nothrow) RprMidiCCLane(rprTake)) { int defaultHeight = 67; // same height FNG versions use (to keep behavior identical) set<int> usedCC = GetUsedCCLanes(MIDIEditor_GetTake(MIDIEditor_GetActive()), 2); for (int i = 0; i < laneView->countShown(); ++i) if (usedCC.find(laneView->getIdAt(i)) == usedCC.end()) laneView->remove(i--); // Special case: Bank select and CC0 (from FNG version to keep behavior identical) if (usedCC.find(0) != usedCC.end() && usedCC.find(CC_BANK_SELECT) != usedCC.end() && !laneView->isShown(131)) laneView->append(131, defaultHeight); for (set<int>::iterator it = usedCC.begin(); it != usedCC.end(); ++it) { if (!laneView->isShown(*it)) laneView->append(*it, defaultHeight); else { for (int i = 0; i < laneView->countShown(); ++i) { if (laneView->getIdAt(i) == *it && laneView->getHeight(i) == 0) laneView->setHeightAt(i, defaultHeight); } } } if (laneView->countShown() == 0) laneView->append(-1, 0); delete laneView; Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ITEMS, -1); } } }
void MainSaveCCLanes(COMMAND_T* _ct) { HWND me = MIDIEditor_GetActive(); MediaItem_Take* tk = me ? MIDIEditor_GetTake(me) : NULL; if (tk) { MediaItem* item = GetMediaItemTake_Item(tk); int tkIdx = GetTakeIndex(item, tk); // NULL item managed if (tkIdx >= 0) { SNM_TakeParserPatcher p(item, CountTakes(item)); WDL_FastString takeChunk; if (p.GetTakeChunk(tkIdx, &takeChunk)) { SNM_ChunkParserPatcher ptk(&takeChunk, false); // check start/end position of lanes in the chunk int firstPos = 0, lastPos = 0, laneCpt = 0; int pos = ptk.Parse(SNM_GET_CHUNK_CHAR, 1, "SOURCE", "VELLANE", laneCpt, 0); while (pos > 0) { lastPos = pos; if (!firstPos) firstPos = pos; pos = ptk.Parse(SNM_GET_CHUNK_CHAR, 1, "SOURCE", "VELLANE", ++laneCpt, 0); } if (firstPos > 0) { firstPos--; // see SNM_ChunkParserPatcher char laneSlot[SNM_MAX_CC_LANES_LEN] = ""; int eolLastPos = lastPos; const char* pp = ptk.GetChunk()->Get(); //ok 'cause read only while (pp[eolLastPos] && pp[eolLastPos] != '\n') eolLastPos++; int i = firstPos, j=0; while (pp[i] && i<eolLastPos && j < (SNM_MAX_CC_LANES_LEN-1) ) { //-1 see string termination if (pp[i] != '\n') laneSlot[j++] = pp[i]; else laneSlot[j++] = '|'; i++; } laneSlot[j] = 0; // store lanes char slot[32] = ""; if (_snprintfStrict(slot, sizeof(slot), "cc_lanes_slot%d", (int)_ct->user + 1) > 0) WritePrivateProfileString("MidiEditor", slot, laneSlot, g_SNM_IniFn.Get()); } } } } }
void ME_SaveNoteSelSlot (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd) { if (MediaItem_Take* take = MIDIEditor_GetTake(MIDIEditor_GetActive())) { int slot = (int)ct->user; for (int i = 0; i < g_midiNoteSel.Get()->GetSize(); i++) { if (slot == g_midiNoteSel.Get()->Get(i)->GetSlot()) return g_midiNoteSel.Get()->Get(i)->Save(take); } g_midiNoteSel.Get()->Add(new BR_MidiNoteSel(slot, take)); } }
void MainCreateCCLane(COMMAND_T* _ct) { bool updated = false; HWND me = MIDIEditor_GetActive(); MediaItem_Take* tk = me ? MIDIEditor_GetTake(me) : NULL; if (tk) { MediaItem* item = GetMediaItemTake_Item(tk); int tkIdx = GetTakeIndex(item, tk); // null item managed there if (tkIdx >= 0) { SNM_TakeParserPatcher p(item, CountTakes(item)); WDL_FastString takeChunk; int tkPos, tklen; if (p.GetTakeChunk(tkIdx, &takeChunk, &tkPos, &tklen)) { SNM_ChunkParserPatcher ptk(&takeChunk, false); // check current lanes bool lanes[SNM_MAX_CC_LANE_ID+1]; int i=0; while(i <= SNM_MAX_CC_LANE_ID) lanes[i++]=false; char lastLaneId[4] = ""; //max in v3.6: "133" int tkFirstPos = 0, laneCpt = 0; int pos = ptk.Parse(SNM_GET_CHUNK_CHAR, 1, "SOURCE", "VELLANE", laneCpt, 1, lastLaneId); while (pos > 0) { if (!tkFirstPos) tkFirstPos = pos; lanes[atoi(lastLaneId)] = true; // atoi: 0 on failure, lane 0 won't be used anyway.. pos = ptk.Parse(SNM_GET_CHUNK_CHAR, 1, "SOURCE", "VELLANE", ++laneCpt, 1, lastLaneId); } if (tkFirstPos > 0) { tkFirstPos--; // see SNM_ChunkParserPatcher // find the first unused index i=1; while(lanes[i] && i <= SNM_MAX_CC_LANE_ID) i++; char newLane[SNM_MAX_CHUNK_LINE_LENGTH] = ""; if (_snprintfStrict(newLane, sizeof(newLane), "VELLANE %d 50 0\n", i) > 0) ptk.GetChunk()->Insert(newLane, tkFirstPos); // "update" take updated = p.ReplaceTake(tkPos, tklen, ptk.GetChunk()); } } } } if (updated) Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(_ct), UNDO_STATE_ALL, -1); }
void ME_RestoreNoteSelSlot (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd) { if (MediaItem_Take* take = MIDIEditor_GetTake(MIDIEditor_GetActive())) { int slot = (int)ct->user; for (int i = 0; i < g_midiNoteSel.Get()->GetSize(); i++) { if (slot == g_midiNoteSel.Get()->Get(i)->GetSlot()) { g_midiNoteSel.Get()->Get(i)->Restore(take); Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ALL, -1); return; } } } }
void ME_PreviewActiveTake (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd) { if (MediaItem_Take* take = MIDIEditor_GetTake(MIDIEditor_GetActive())) { MediaItem* item = GetMediaItemTake_Item(take); vector<int> options = GetDigits((int)ct->user); int toggle = options[0]; int type = options[1]; int selNotes = options[2]; int pause = options[3]; MediaTrack* track = GetMediaItem_Track(item); double volume = GetMediaItemInfo_Value(item, "D_VOL"); double start = 0; double measure = (type == 3) ? 1 : 0; bool pausePlay = (pause == 2) ? true : false; if (type == 2) { double mousePosition = ME_PositionAtMouseCursor(true, true); if (mousePosition != -1) start = mousePosition - GetMediaItemInfo_Value(item, "D_POSITION"); else return; } vector<int> muteState; if (selNotes == 2 && !AreAllNotesUnselected(take)) muteState = MuteSelectedNotes(take); MidiTakePreview(toggle, take, track, volume, start, measure, pausePlay); if (muteState.size() > 0) SetMutedNotes(take, muteState); } }
void ME_PreviewActiveTake (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd) { HWND midiEditor = MIDIEditor_GetActive(); if (MediaItem_Take* take = MIDIEditor_GetTake(midiEditor)) { MediaItem* item = GetMediaItemTake_Item(take); vector<int> options = GetDigits((int)ct->user); int toggle = options[0]; int type = options[1]; int selNotes = options[2]; int pause = options[3]; MediaTrack* track = GetMediaItem_Track(item); double volume = GetMediaItemInfo_Value(item, "D_VOL"); double start = 0; double measure = (type == 3) ? 1 : 0; bool pausePlay = (pause == 2) ? true : false; if (type == 2) { double mousePosition = ME_PositionAtMouseCursor(true, true); if (mousePosition != -1) { if (GetToggleCommandState2(SectionFromUniqueID(SECTION_MIDI_EDITOR), 40470) > 0) // Timebase: Beats(source) start = mousePosition - MIDI_GetProjTimeFromPPQPos(take, 0); else start = mousePosition - GetMediaItemInfo_Value(item, "D_POSITION"); } else return; } vector<int> muteState; if (selNotes == 2) { if (!AreAllNotesUnselected(take)) { muteState = MuteUnselectedNotes(take); if (type != 2) { BR_MidiEditor editor(midiEditor); double time; MIDI_GetNote(take, FindFirstSelectedNote(take, &editor), NULL, NULL, &time, NULL, NULL, NULL, NULL); start = MIDI_GetProjTimeFromPPQPos(take, time) - GetMediaItemInfo_Value(item, "D_POSITION"); if (start < 0) start = 0; } } else if (type != 2) { BR_MidiEditor editor(midiEditor); int id = FindFirstNote(take, &editor); if (id != -1) { double time; MIDI_GetNote(take, id, NULL, NULL, &time, NULL, NULL, NULL, NULL); start = MIDI_GetProjTimeFromPPQPos(take, time) - GetMediaItemInfo_Value(item, "D_POSITION"); if (start < 0) start = 0; } } } MidiTakePreview(toggle, take, track, volume, start, measure, pausePlay); if (muteState.size() > 0) SetMutedNotes(take, muteState); } }
RprTake RprTake::createFromMidiEditor() { void *midiEditor = MIDIEditor_GetActive(); RprTake take(MIDIEditor_GetTake(midiEditor)); return take; }