public void draw(Graphics2D g, int width, int height) { if (mMainForm == null) { return; } lock (AppManager.mDrawObjects) { g.setColor(mBackgroundColor); g.fillRect(0, 0, width, height); g.setStroke(getStroke2px()); g.setColor(FormMain.mColorNoteFill); int key_width = AppManager.keyWidth; int xoffset = key_width + AppManager.keyOffset; VsqFileEx vsq = AppManager.getVsqFile(); int overview_dot_diam = 2; int selected = AppManager.getSelected(); List <DrawObject> objs = AppManager.mDrawObjects[selected - 1]; // 平均ノートナンバーを調べる double sum = 0.0; int count = 0; foreach (var dobj in objs) { if (dobj.mType == DrawObjectType.Note) { sum += dobj.mNote; count++; } } float average_note = (float)(sum / (double)count); foreach (var dobj in objs) { int x = (int)(dobj.mClock * mOverviewPixelPerClock); if (x < 0) { continue; } if (width - key_width < x) { break; } int y = height - (height / 2 + (int)((dobj.mNote - average_note) * overview_dot_diam)); int length = (int)(dobj.mLength * mOverviewPixelPerClock); if (length < overview_dot_diam) { length = overview_dot_diam; } g.drawLine(x + xoffset, y, x + length + xoffset, y); } g.setStroke(getStrokeDefault()); int current_start = AppManager.clockFromXCoord(key_width); int current_end = AppManager.clockFromXCoord(mMainForm.pictPianoRoll.getWidth()); int x_start = (int)(current_start * mOverviewPixelPerClock); int x_end = (int)(current_end * mOverviewPixelPerClock); // 小節ごとの線 int clock_start = 0; int clock_end = (int)(width / mOverviewPixelPerClock); int premeasure = vsq.getPreMeasure(); g.setClip(null); Color pen_color = new java.awt.Color(0, 0, 0, 130); int barcountx = 0; string barcountstr = ""; for (Iterator <VsqBarLineType> itr = vsq.getBarLineIterator(clock_end * 3 / 2); itr.hasNext();) { VsqBarLineType bar = itr.next(); if (bar.clock() < clock_start) { continue; } if (width - key_width < barcountx) { break; } if (bar.isSeparator()) { int barcount = bar.getBarCount() - premeasure + 1; int x = (int)(bar.clock() * mOverviewPixelPerClock); if ((barcount % 5 == 0 && barcount > 0) || barcount == 1) { g.setColor(pen_color); g.setStroke(getStroke2px()); g.drawLine(x + xoffset, 0, x + xoffset, height); g.setStroke(getStrokeDefault()); if (!barcountstr.Equals("")) { g.setColor(Color.white); g.setFont(AppManager.baseFont9); g.drawString(barcountstr, barcountx + 1 + xoffset, 1 + AppManager.baseFont9Height / 2 - AppManager.baseFont9OffsetHeight + 1); } barcountstr = barcount + ""; barcountx = x; } else { g.setColor(pen_color); g.drawLine(x + xoffset, 0, x + xoffset, height); } } } g.setClip(null); } }
/// <summary> /// numStartBar, numStartBeat, numEndBar, numEndBeatの値の範囲の妥当性をチェックする /// </summary> private void validateNumRange() { int startBar = getStartBar(); int startBeat = getStartBeat(); int endBar = getEndBar(); int endBeat = getEndBeat(); VsqFileEx vsq = AppManager.getVsqFile(); if (vsq == null) { return; } int preMeasure = vsq.getPreMeasure(); startBar += (preMeasure - 1); // 曲頭からの小節数は、表示上の小節数と(preMeasure - 1)だけずれているので。 endBar += (preMeasure - 1); startBeat--; endBeat--; int startBarClock = vsq.getClockFromBarCount(startBar); // startBar小節開始位置のゲートタイム Timesig startTimesig = vsq.getTimesigAt(startBarClock); // startBar小節開始位置の拍子 int startClock = startBarClock + startBeat * 480 * 4 / startTimesig.denominator; // 第startBar小節の第startBeat拍開始位置のゲートタイム int endBarClock = vsq.getClockFromBarCount(endBar); Timesig endTimesig = vsq.getTimesigAt(endBarClock); int endClock = endBarClock + endBeat * 480 * 4 / endTimesig.denominator; if (endClock <= startClock) { // 選択範囲が0以下の場合、値を強制的に変更する // ここでは、一拍分を選択するように変更 endClock = startClock + 480 * 4 / startTimesig.denominator; endBar = vsq.getBarCountFromClock(endClock); int remain = endClock - vsq.getClockFromBarCount(endBar); endTimesig = vsq.getTimesigAt(endClock); endBeat = remain / (480 * 4 / endTimesig.denominator); } // numStartBarの最大値・最小値を決定 int startBarMax = endBar - 1; if (startBeat < endBeat) { startBarMax = endBar; } int startBarMin = 1; // numStartBeatの最大値・最小値を決定 int startBeatMax = startTimesig.numerator; if (startBar == endBar) { startBeatMax = endBeat - 1; } int startBeatMin = 1; // numEndBarの最大値・最小値を決定 int endBarMax = int.MaxValue; int endBarMin = startBar + 1; if (startBeat < endBeat) { endBarMin = startBar; } // numEndBeatの最大値・最小値の決定 int endBeatMax = endTimesig.numerator; int endBeatMin = 1; if (startBar == endBar) { endBeatMin = startBeat + 1; } lockRequired = true; numStartBar.Maximum = startBarMax; numStartBar.Minimum = startBarMin; numStartBeat.Maximum = startBeatMax; numStartBeat.Minimum = startBeatMin; numEndBar.Maximum = endBarMax; numEndBar.Minimum = endBarMin; numEndBeat.Maximum = endBeatMax; numEndBeat.Minimum = endBeatMin; lockRequired = false; }