Skip to content

Commit

Permalink
visual fixes. triplets are marked with the number "3" on the left sin…
Browse files Browse the repository at this point in the history
…ce now (classic music notation is still better it hink, but its at least something)
  • Loading branch information
klesun committed Jul 31, 2015
1 parent 77d8fb5 commit 3ed9eba
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 49 deletions.
20 changes: 9 additions & 11 deletions src/blockspace/staff/PianoLayoutPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void drawVanBascoLikePianoLayout(Rectangle baseRect, Graphics g)

Set<INota> highlightEm = getNotaSet();

// draw base piano layout
int firstTune = 36;
int tuneCount = 72; // 6 octaves

Expand Down Expand Up @@ -94,24 +93,23 @@ private void drawVanBascoLikePianoLayout(Rectangle baseRect, Graphics g)
});
}

private Set<INota> getNotaSet()
synchronized private Set<INota> getNotaSet()
{
Set<INota> result = new TreeSet<>();

int index = staff.getFocusedIndex();
Fraction sum = new Fraction(0);
if (index > -1) {
Fraction sum = staff.getAccordList().get(index).getFraction().negate();

while (sum.compareTo(ImageStorage.getTallLimit()) < 0) {
while (sum.compareTo(ImageStorage.getTallLimit()) < 0 && index > -1) {

Accord accord = staff.getAccordList().get(index);
Accord accord = staff.getAccordList().get(index);
sum = sum.add(accord.getFraction());

final Fraction finalSum = sum;
accord.notaStream(n -> n.getRealLength().compareTo(finalSum) > 0).forEach(result::add);
final Fraction finalSum = sum;
accord.notaStream(n -> n.getRealLength().compareTo(finalSum) > 0).forEach(result::add);

if (--index >= 0) {
sum = sum.add(staff.getAccordList().get(index).getFraction());
} else {
break;
--index;
}
}

Expand Down
18 changes: 2 additions & 16 deletions src/blockspace/staff/accord/Accord.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import model.field.Field;
import model.SimpleAction;
import blockspace.staff.MidianaComponent;
import stuff.tools.Fp;
import stuff.tools.jmusic_integration.INota;
import org.apache.commons.math3.fraction.Fraction;

Expand Down Expand Up @@ -64,21 +65,11 @@ private static Consumer<Graphics> slogPainting(Rectangle r, String value) {
return g -> {
if (g.getFontMetrics(g.getFont()).stringWidth(value) > 0) {
g.setColor(Color.BLACK);
g.setFont(scaleFont(value, r, g));
g.drawString(value, 0, 0);
Fp.fitTextIn(r, value, g);
}
};
}

private static Font scaleFont(String text, Rectangle rect, Graphics g) {
float fontSize = 20.0f;

Font font = g.getFont().deriveFont(fontSize);
int width = g.getFontMetrics(font).stringWidth(text);
fontSize = (rect.width / width ) * fontSize;
return g.getFont().deriveFont(fontSize);
}

// responses to events (actions)

public Explain<Boolean> moveFocus(int n) {
Expand Down Expand Up @@ -115,11 +106,6 @@ public long getEarliestKeydown() {
return nota != null ? nota.keydownTimestamp : 0;
}

public Boolean isHighestBotommedToFitSystem() {
Nota nota = this.getNotaSet().stream().reduce(null, (a, b) -> a != null && a.tune.get() > b.tune.get() ? a : b);
return nota != null ? nota.isBotommedToFitSystem() : false;
}

public Nota findByTuneAndChannel(int tune, int channel) {
return this.getNotaSet().stream().filter(n -> n.tune.get() == tune && n.getChannel() == channel).findFirst().orElse(null);
}
Expand Down
6 changes: 3 additions & 3 deletions src/blockspace/staff/accord/nota/Nota.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void drawOn(Graphics surface, int x, int y, Boolean completeRepaint) {
surface.drawImage(tmpImg, x + getNotaImgRelX(), y, null);

if (isTriplet.get()) {
for (int i = 0; i < 3; ++i) {
surface.drawLine(x + getStickX(), y + i * 2 + 1, x + getStickX() - 6, y + i * 2 + 1);
}
surface.setColor(ImageStorage.getColorByChannel(channel.get()));
Rectangle rect = new Rectangle(x + dx() /4, y + 6 * dy(), dx() / 2, dy() * 2);
Fp.fitTextIn(rect, "3", surface);
}

for (int i = 0; i < getDotCount(); ++i) {
Expand Down
8 changes: 4 additions & 4 deletions src/gui/ImageStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public static Color getBetween(Color start, Color end, Fraction factor) {

public static Color getColorByChannel(int n) {
return n == 0 ? new Color(0,0,0) : // black
n == 1 ? new Color(255,0,0) : // red
n == 2 ? new Color(0,192,0) : // green
n == 3 ? new Color(0,0,255) : // blue
n == 4 ? new Color(191,191,0) : // yellow
n == 1 ? new Color(192,0,0) : // red
n == 2 ? new Color(0,148,0) : // green
n == 3 ? new Color(48,48,255) : // blue
n == 4 ? new Color(128,128,0) : // yellow
n == 5 ? new Color(0,127,255) : // cyan
n == 6 ? new Color(192,0,192) : // magenta
n == 7 ? new Color(255,128,0) : // orange
Expand Down
8 changes: 4 additions & 4 deletions src/stuff/Midi/DeviceEbun.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ public static void setVolume(int channel, int value) {
sendMessage(ShortMessage.CONTROL_CHANGE, channel, VOLUME, value);
}

public static void openNota(INota nota) {
synchronized public static void openNota(INota nota) {
openNotaSet.add(nota);
if (nota.getChannel() != DRUM_CHANNEL) {
sendMessage(ShortMessage.NOTE_ON, nota.getChannel(), nota.getTune(), nota.getVolume());
} else {
sendMessage(DRUM_NOTE_ON, nota.getTune(), nota.getVolume());
}
openNotaSet.add(nota);
}

public static void closeNota(INota nota) {
synchronized public static void closeNota(INota nota) {
openNotaSet.remove(nota);
if (nota.getChannel() != DRUM_CHANNEL) {
sendMessage(ShortMessage.NOTE_OFF, nota.getChannel(), nota.getTune(), 0);
} else {
sendMessage(DRUM_NOTE_OFF, nota.getTune(), 0);
}
openNotaSet.remove(nota);
}

public static void closeAllNotas() {
Expand Down
11 changes: 0 additions & 11 deletions src/stuff/test/hujGuzno.java

This file was deleted.

19 changes: 19 additions & 0 deletions src/stuff/tools/Fp.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package stuff.tools;

import gui.Constants;

import java.awt.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class Fp {
// TODO: make static class Settings, where we will store scaling koef and the stuff
Expand Down Expand Up @@ -48,6 +51,22 @@ public static void drawParabola(Graphics2D g, Rectangle r) {
g.setStroke(tmpStroke);
}

public static void fitTextIn(Rectangle rect, String text, Graphics g) {

Function<Integer, Double> toInches = pixels -> pixels * 1.25;
Function<Double, Double> toPixels = inches -> inches * 0.8;

double fontSize = toInches.apply(rect.height);

Font font = Constants.PROJECT_FONT.deriveFont((float)fontSize);
int width = g.getFontMetrics(font).stringWidth(text);
fontSize = Math.min(fontSize * rect.width / width, fontSize);

g.setFont(Constants.PROJECT_FONT.deriveFont((float)fontSize));

g.drawString(text, rect.x, rect.y + toPixels.apply(fontSize).intValue());
}

// TODO: this method was written on quick hand - don't judge strict, but better - improve!
public static String traceDiff(Throwable trace1, Throwable trace2)
{
Expand Down

0 comments on commit 3ed9eba

Please sign in to comment.