Skip to content

Commit

Permalink
ux fix so note did not disappear when trying to assign same channel i…
Browse files Browse the repository at this point in the history
…t already has
  • Loading branch information
klesun committed Oct 16, 2015
1 parent 879da67 commit 73334eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
14 changes: 10 additions & 4 deletions src/org/shmidusic/sheet_music/staff/chord/nota/NotaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ private static ContextAction<NoteComponent> mkFailableAction(Function<NoteCompon
}

synchronized private static void changeChannel(NoteComponent nota, int channel) {
JSONObject js = nota.note.getJsonRepresentation();
js.put(nota.note.channel.getName(), channel);
nota.getParentComponent().addNewNota(js);
nota.getParentComponent().remove(nota.note);

Boolean canChange = nota.getParentComponent().chord.notaStream()
.noneMatch(n -> n.channel.get() == channel && n.tune.get() == nota.note.tune.get());

if (canChange) {
JSONObject js = nota.note.getJsonRepresentation();
js.put(nota.note.channel.getName(), channel);
nota.getParentComponent().addNewNota(js);
nota.getParentComponent().remove(nota.note);
}
}
}
28 changes: 10 additions & 18 deletions src/org/shmidusic/stuff/musica/PlaybackTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
public class PlaybackTimer implements IMidiScheduler {

final private StaffConfig config;
private Thread timerThread = null;

private Boolean stop = false;

Expand Down Expand Up @@ -45,27 +44,23 @@ public void appendTask(Fraction delta, Runnable task) {
}

public void start() {
this.timerThread = new Thread(() -> {
long startTime = System.currentTimeMillis();
iterate(startTime);
});
this.timerThread.start();
long startTime = System.currentTimeMillis();
iterate(startTime);
}

private void iterate(long startTime)
{
if (!stop) {
synchronized (tasks) {
long now = System.currentTimeMillis();

Fraction from = new Fraction(0);
Fraction to = tasks.navigableKeySet().stream().filter(f -> startTime + toMillis(f) > now).findFirst().orElse(new Fraction(Integer.MAX_VALUE));
Set<Fraction> keys = tasks.navigableKeySet().subSet(from, to);
long now = System.currentTimeMillis();

for (Fraction key : keys) {
List<Runnable> taskList = tasks.remove(key);
taskList.forEach(Runnable::run);
}
Fraction from = new Fraction(0);
Fraction to = tasks.navigableKeySet().stream().filter(f -> startTime + toMillis(f) > now).findFirst().orElse(new Fraction(Integer.MAX_VALUE));
Set<Fraction> keys = tasks.navigableKeySet().subSet(from, to);

for (Fraction key : keys) {
List<Runnable> taskList = tasks.remove(key);
taskList.forEach(Runnable::run);
}

if (tasks.size() > 0) {
Expand All @@ -84,9 +79,6 @@ private void iterate(long startTime)

synchronized public void interrupt() {
this.stop = true;
if (this.timerThread != null) {
this.timerThread.interrupt();
}
}

protected long toMillis(Fraction f) {
Expand Down

0 comments on commit 73334eb

Please sign in to comment.