internal abstract void PlayPedal(bool on); //invoked during sustain change (e.g. pedal action) internal static clsSustain New(clsSustain oldsustain) { if (oldsustain == null) { PlayPedalStatic(false); //switch off any old sustain } if (P.F == null || P.frmSC == null) { return(new clsSustainNormal(oldsustain)); } if (P.frmSC.optSustainNormal.Checked) { return(new clsSustainNormal(oldsustain)); } else if (P.frmSC.optSustainCarryOver.Checked) { return(new clsSustainCarryOver(oldsustain)); } else if (P.frmSC.optSustainReplay.Checked) { return(new clsSustainReplay(oldsustain)); } else if (P.frmSC.optSustainSendCtlr.Checked) { return(new clsSustainSendCtlr(oldsustain)); } else { LogicError.Throw(eLogicError.X071); return(new clsSustainNormal(oldsustain)); } }
internal static int GetBlackDiff(int blackkey, int whitekey) { // calculate number of black keys between whitekey and blackkey // <0: blackkey lower // >0: blackkey higher int dir = 1; if (blackkey < whitekey) { dir = -1; } if (!clsMidiInKB.IsBlackKey(blackkey) || clsMidiInKB.IsBlackKey(whitekey)) { LogicError.Throw(eLogicError.X027); return(dir); } int cnt = 1; for (int i = whitekey; i != blackkey; i += dir) { if (clsMidiInKB.IsBlackKey(i)) { cnt++; } } return(cnt * dir); }
internal static void CmdState_Set() { if (P.F.FSTrackMap == null && P.F.AudioSync == null) { CmdState_Disable(); return; } switch (MidiPlay.Sync.indPlayActive) { case clsSync.ePlay.MidiStream: case clsSync.ePlay.AudioStream: CmdState_Playing(); return; case clsSync.ePlay.SyncActive: CmdState_Disable(); return; case clsSync.ePlay.SyncEnabled: CmdState_Disable(); return; case clsSync.ePlay.None: CmdState_Stopped(); return; default: LogicError.Throw(eLogicError.X100); return; } }
private int SetKBMap(int[] nextnote, int k) { if (KBMap[k] < 0) { return(-1); //black note } int prevn = -1; int q = KBMap[k] / 12; //octave int m = KBMap[k].Mod12(); //note 0-11 int n = nextnote[m] + 12 * q; if (n - KBMap[k] > +6) { n -= 12; } if (n - KBMap[k] < -6) { n += 12; } if (n < prevn) //not sure if this can happen! { LogicError.Throw(eLogicError.X028); return(n); } prevn = n; return(n); }
private void ChordsRawToRun() { //* convert ChordsRaw to ChordsRun string runningtxt = "#"; for (int b = 0; b < BeatToBBT[NumBeats].Beats; b++) //BarToBBT includes bar after last (Numbars+1) { clsMTime.clsBBT bbt = BeatToBBT[b]; int bar = bbt.Bar; int beat = bbt.BeatsRemBar; clsChord chord = ChordsRaw[bar, beat]; string txt = chord.Txt; if (txt == null || txt == "") { LogicError.Throw(eLogicError.X006, "txt = " + txt); //invalid beat (> NN) or not raw ChordsRun[bar, beat] = new clsChord("", 0); } //if (txt != runningtxt || (beat == 0 && P.F.CF.Sections.Boundaries[bar])) { //if (txt != runningtxt || P.F.CF.QSections.FirstBeatName(bbt) != '*') { if (txt != runningtxt || (bar == 0 && beat == 0)) { ChordsRun[bar, beat] = chord.Copy(); } else { ChordsRun[bar, beat] = new clsChord("", 0); } runningtxt = txt; } }
internal static clsMTime.clsSegment GetStartSeg(eAlign align, int qilo, int qihi, int qiwidth, int ticksperqi) { clsMTime.clsSegment startseg; switch (align) { case eAlign.Bar: startseg = new clsMTime.clsSegBar(ticksperqi, qilo, qihi); break; case eAlign.Beat: startseg = new clsMTime.clsSegBeat(ticksperqi, qilo, qihi); break; case eAlign.HalfBar: startseg = new clsMTime.clsSegHalfBar(ticksperqi, qilo, qihi); break; case eAlign.Interval: startseg = new clsMTime.clsSegInterval(ticksperqi, qilo, qihi, qiwidth); break; default: LogicError.Throw(eLogicError.X067); startseg = new clsMTime.clsSegBeat(ticksperqi, qilo, qihi); break; } return(startseg); }
internal void CreateOnOffPairs() { //* create onoff pairs for all tracks aggregated from pitch classes bool thismapq, prevmapq; int onq = -1; for (int n = 0; n < 12; n++) //modded note { prevmapq = false; OnOffPairs[n] = new clsOnOffPairs(); //for (int q = 0; q < this.GetLengthQTime(); q++) { for (int q = 0; q < P.F.MaxBBT.QI; q++) { //thismapq = this[q, n]; thismapq = this[q, n]; if (thismapq && !prevmapq) //ON { onq = q; } else if (!thismapq && prevmapq) //OFF { if (onq < 0) { LogicError.Throw(eLogicError.X078); continue; } OnOffPairs[n].Add(onq, q); onq = -1; } prevmapq = thismapq; } } }
private void ApplyBezier(byte[] b) { int status = b[0] & 0xf0; int outval = 0; if (status == 0x90 && b[2] > 0 && Cfg.BezierVel >= 0) //ON ev (-1 = "None") { if (b[2] > 127) { LogicError.Throw(eLogicError.X095); } else { outval = Beziers[Cfg.BezierVel].KBtoMidiVel[b[2]]; } if (P.frmCfgBezier != null && P.frmCfgBezier.IsHandleCreated) { P.frmCfgBezier.Monitor(b[2], outval, true); } b[2] = (byte)outval; } else if (status == 0xd0) //aftertouch { int inval = b[1]; outval = Beziers[Cfg.BezierATouch].KBtoMidiVel[b[1]]; if (P.frmCfgBezier != null && P.frmCfgBezier.IsHandleCreated) { P.frmCfgBezier.Monitor(inval, outval, false); } b[1] = (byte)outval; } }
internal void Add(int ticks, T val) { //if (val == null) { // LogicError.Throw(eLogicError.X052); // return; //} if (Keys.Count > 0) { if (Keys[Count - 1] == ticks) { return; //use first key only } if (Keys[Count - 1] > ticks) //assumed infrequent! { int index = Keys.BinarySearch(ticks); if (index >= 0) { return; //key already exists - use first key only } index = ~index; //index after ticks Keys.Insert(index, ticks); Values.Insert(index, val); LogicError.Throw(eLogicError.X157); //not in order - warning (for now) return; } } Keys.Add(ticks); Values.Add(val); }
public void SendEvents(byte[] bytes) { //* QIPlay only if (bytes.Length < 3) { return; } if (bytes[1] < 0x80) //no initial status byte { LogicError.Throw(eLogicError.X058); return; } byte[] msg = new byte[4]; //status, msg, data, 0 (time - ignore) int msgindex = 0; for (int i = 1; i < bytes.Length; i++) //ignore first 0 { byte b = bytes[i]; if (b >= 0x80 && i > 1) { SendShortMsgQI(msg[0], msg[1], msg[2]); msgindex = 0; msg.Initialize(); } msg[msgindex++] = b; } SendShortMsgQI(msg[0], msg[1], msg[2]); }
internal static void SetConfig() { if (UpdatePeriod < 5) { LogicError.Throw(eLogicError.X160); return; } //CheckOK(Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, UpdatePeriod)); Bass.UpdatePeriod = UpdatePeriod; BassInfo info = new BassInfo(); if (Bass.GetInfo(out info)) { BassInfo = info; if (P.frmConfigBass != null) { P.frmConfigBass.lblMinBuf.Text = BassInfo.MinBufferLength.ToString(); P.frmConfigBass.lblLatency.Text = BassInfo.Latency.ToString(); } if (BufferSize <= 10) //10 is min, but may be defaulted to by BASS { int minbuf = (BassInfo.MinBufferLength > 0) ? BassInfo.MinBufferLength : 100; BufferSize = UpdatePeriod + minbuf + BufferMargin; if (P.frmConfigBass != null) { P.frmConfigBass.Bypass_Event = true; P.frmConfigBass.nudBuffer.Value = BufferSize; P.frmConfigBass.Bypass_Event = false; } } } //CheckOK(Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, BufferSize)); Bass.PlaybackBufferLength = BufferSize; }
internal void Add(int midikey, string scale, int ticks) { //* called by loadmidifile if (Keys.Count > 0) { clsKeyTicks prevkey = Keys[Keys.Count - 1]; //if (ticks < prevkey.Ticks) throw new FatalException(); if (ticks < prevkey.Ticks) { LogicError.Throw(eLogicError.X081); return; } clsMTime.clsBBT bbt = new clsMTime.clsBBT(ticks); //should have (partial) mtime created by now if (bbt.TicksRemBeat != 0) { LogicError.Throw(eLogicError.X104, "key ticks not aligned to bar"); clsMTime.clsBBT bbtbar = new ChordCadenza.clsMTime.clsBBT(bbt.Bar, 0, 0); ticks = bbtbar.Ticks; } if (ticks == prevkey.Ticks) { //* replace key, but retain ticks Keys.RemoveAt(Keys.Count - 1); Keys.Add(new clsKeyTicks(midikey, scale, prevkey.Ticks)); return; } } Keys.Add(new clsKeyTicks(midikey, scale, ticks)); Finish(); }
internal clsChordInfo(eAlign align) { if (Align == eAlign.Auto) { LogicError.Throw(eLogicError.X084); } Align = align; }
internal clsBBT(int beats, bool indbeats) { if (!indbeats) { LogicError.Throw(eLogicError.X018); } MTime = P.F.MTime; NewBBTBeat(beats); }
internal clsBBT(clsMTime mtime, int beats, bool indbeats) { if (!indbeats) { LogicError.Throw(eLogicError.X019); } MTime = mtime; NewBBTBeat(beats); }
internal static void LoadToolTips(Form form) { if (!(form is ITT)) { LogicError.Throw(eLogicError.X141, form.Name); } ToolTip tt; LoadToolTips(form, out tt); }
internal T(clsTrks trks, int trk) { Trks = trks; if (trk >= trks._NumTrks || trk < 0) { LogicError.Throw(eLogicError.X144); //TrkNum = 0; } TrkNum = trk; }
internal bool?TransposeNamesSharp = null; //#/b/null for transposed names keys (not these keys!) //internal List<string> Desc = new List<string>; //private clsMTime MTime; internal clsKeyTicks(int keynote, string scale, int ticks, bool indkeynote) { if (!indkeynote) { LogicError.Throw(eLogicError.X014); } Init(scale, ticks); KeyNote = keynote; MidiKey = NoteName.PitchToMidiKey(KeyNote, scale, null); KeyNoteStr = NoteName.MidiKeyToKeyStr(MidiKey, Scale); }
protected static int CheckHandle(int handle) { if (handle != 0) { return(handle); } Errors error = Bass.LastError; LogicError.Throw(eLogicError.X117); return(0); }
protected override int RoundDownQI(int qi) { //* round down segshi to end global with a complete segment clsBBT bbt = (new clsBBT(qi * TicksPerQI)); RoundDown(bbt); if (bbt.Ticks % TicksPerQI != 0) { LogicError.Throw(eLogicError.X017); } return(bbt.Ticks / TicksPerQI); }
protected override int RoundUpQI(int qi) { //* round up segslo to start global at start of complete segment clsBBT bbt = (new clsBBT(qi * TicksPerQI)); RoundUp(bbt); if (bbt.Ticks % TicksPerQI != 0) { LogicError.Throw(eLogicError.X016); } return(bbt.Ticks / TicksPerQI); }
protected int NextSegQI() { int qi = SegQILo; clsBBT bbt = (new clsBBT(qi * TicksPerQI)); NextSeg(bbt); if (bbt.Ticks % TicksPerQI != 0) { LogicError.Throw(eLogicError.X026); } return(bbt.Ticks / TicksPerQI); }
private void ChordsRawToNoteMap(clsChord[,] copy) { //* update notemap with chord changes for (int b = 0; b < NumBeats; b++) { clsMTime.clsBBT bbt = BeatToBBT[b]; int bar = bbt.Bar; int beat = bbt.BeatsRemBar; clsChord chord = ChordsRaw[bar, beat]; if (chord.Txt == "***") { continue; } if (copy[bar, beat].IsEquiv(chord)) { continue; } string txt = chord.Txt; //* transpose if necessary //int diff = (Frm.ChordTransposeNamesVal - Frm.ChordTransposeNotesVal).Mod12(); int diff = Frm.TransposeChordNamesVal; if (diff != 0 && txt != "null") { string qualifier; int pc = NoteName.GetPitchAndQualifier(chord.Txt, out qualifier); if (pc < 0) { LogicError.Throw(eLogicError.X007, "pc = " + pc); pc = 0; } pc = Frm.ChordTransposeReverse(pc); txt = NoteName.PitchToKeyStr(pc, P.F.Keys[0].Scale).TrimEnd() + qualifier; } int qilo = bbt.Ticks / P.F.TicksPerQI; int qihi = new clsMTime.clsBBT(b + 1, true).Ticks / P.F.TicksPerQI; if (qihi > P.F.MaxBBT.QI) { break; //??? } string dottxt = (chord.Txt == "null") ? "null" : "." + txt; if (!P.F.CF.NoteMap.PropagateNoteMapBeat(bbt, dottxt, qilo, qihi)) { LogicError.Throw(eLogicError.X008); P.F.CF.NoteMap.PropagateNoteMapBeat(bbt, "null", qilo, qihi); } } //Frm.picNoteMapFile.Refresh(); Frm.RefreshpicNoteMapFile(); }
//internal bool GetMapPB(int qtime, int note, bool mod) { //all trks // //*( return true if any trk has a note with no pitchbend // for (int trk = 0; trk < NumTrks; trk++) { // if (GetMapPB(qtime, note, trk, mod)) return true; // } // return false; //} //public override bool this[int qtime, int note] { //all trks // get { // return (_Map[qtime, note] != 0); // } // set { // throw new LogicException(); // } //} public override bool[] this[int qtime] { //return bool[12] array for all trks get { ushort ushrt = 0; foreach (ushort[] s in _Map) { ushrt |= s[qtime]; } return(UShortToBoolArray(ushrt)); } set { LogicError.Throw(eLogicError.X064); } }
public bool[] this[int qtime, bool mod, bool indtrk, bool noch9] { //* return bool[12 or 128 or 12*numtrks or 128*numtrks] array //* indtrk=true: check each track individually get { if (!indtrk) { return(this[qtime, mod, noch9]); } if (mod) //mod and trk { BigInteger big = 0; int size = 0; foreach (clsTrks.T trk in P.F.Chan.Next) { if (noch9 && P.F.Chan[trk] == 9) { continue; } if (trk.TrkNum > 0) { big <<= 12; } big |= _Map[trk][qtime]; size += 12; } return(BigIntegerToBoolArray(big, size)); } else //unmodded and trk { BigInteger big = 0; int size = 0; foreach (clsTrks.T trk in P.F.Chan.Next) { if (noch9 && P.F.Chan[trk] == 9) { continue; } if (trk.TrkNum > 0) { big <<= 128; } big |= _FullMap[trk][qtime]; size += 128; } return(BigIntegerToBoolArray(big, size)); } } set { LogicError.Throw(eLogicError.X066); } }
internal static void MidiOutShortMsg(int status, int msg, int data) { if (NoMon) { return; } //* OutKB only if (Bypass) { return; } int stat = (status & 0xf0); if (stat != 0x80 && stat != 0x90) { return; } int chan = (status & 0x0f); if (chan != MidiPlay.KBOutChan) { #if DEBUG MessageBox.Show("Wrong channel on MidiMon.MidiOutShortMsg"); Debugger.Break(); #endif return; } if (stat == 0x90 && data > 0) //note ON { if (!Pitches[msg]) { PitchCount++; } Pitches[msg] = true; } else if (stat == 0x80 || (stat == 0x90 && data == 0)) //note OFF { if (Pitches[msg]) { PitchCount--; } if (PitchCount < 0) { LogicError.Throw(eLogicError.X165); PitchCount = 0; } Pitches[msg] = false; } }
private void SelectAlign() { //* create listci from ListCIArr[0/1] ListCI = new List <clsChordInfo>(250); //final chord list if (Align == eAlign.Auto) { //* create listci... from listciarr[0/1/2] ListCIBar = ListCIArr[0]; ListCIHalfBar = ListCIArr[1]; ListCIBeat = ListCIArr[2]; Bars = new List <clsBarSubHB>(250); //* get bar/halfbar/beat structure GetStructure(); //* calculate minimum unweighted scores MinScores = new List <clsCompScores>(250); for (int b = 0; b < Bars.Count; b++) { clsBarSubHB bar = Bars[b]; clsCompScores min = new clsCompScores(bar); MinScores.Add(min); if (MinScores.Count != b + 1) { LogicError.Throw(eLogicError.X086); } } //* calculate weighted bar score combinations CalcWeightedScores(); int hbindex = 0, beatindex = 0; for (int bar = 0; bar < Bars.Count; bar++) { clsWeightedScores w = WeightedScores[bar]; clsChordInfo[] cibar = w.MaxCombo.SelectAuto(bar); if (DebugChords) { DebugBarScores(ref hbindex, ref beatindex, bar); DebugComboScore(bar, cibar); } ListCI.AddRange(cibar); } } else { ListCI = ListCIArr[0]; } }
static GeneralMidiList() { List <string> lines = Utils.ReadLines(Cfg.GeneralMidiDatFilePath); char[] delimspace = new char[] { ' ' }; for (int i = 0; i < 128; i++) { string[] f = lines[i].Split(delimspace, 2); if (int.Parse(f[0]) != i + 1) { LogicError.Throw(eLogicError.X050); } Desc[i] = f[1]; } }
internal void CopySeg(int srcqi, int destqi, int qilen, int transpose) { //* copy segment within NewMap (eg bar) if (Math.Abs(srcqi - destqi) < qilen) //no overlap allowed { LogicError.Throw(eLogicError.X060); return; } //P.F.CF.UndoRedoCF.StartEvs(); for (int i = 0; i < qilen; i++) { bool[] newchord = Transpose(this[srcqi + i], transpose); SetChordAndAtts(destqi + i, newchord); //-> calc chordatts } }
public override bool this[int qtime, int note] { //all trks (modded) get { foreach (ushort[] x in _Map) { if ((x[qtime] & NoteMask12[note]) > 0) { return(true); } } return(false); } set { LogicError.Throw(eLogicError.X062); } }