blob: ddfc5ff71d9bb93f797bd5d0fb89633769147777 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*******************************************************************************
* Copyright (c) 2008, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.examples.core.midi.launcher;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.examples.core.pda.DebugCorePlugin;
/**
* Controls the location of the sequencer in microseconds.
*
* @since 1.0
*/
public class ClockControl extends TimeControl {
/**
* @param launch
*/
public ClockControl(MidiLaunch launch) {
super("Time" , launch); //$NON-NLS-1$
}
@Override
protected long getTimeValue() {
return getSequencer().getMicrosecondPosition();
}
@Override
public boolean isEditable() {
return true;
}
@Override
public IStatus setValue(String newValue) {
try {
long value = getLong(newValue);
getSequencer().setMicrosecondPosition(value);
fireEvent(new DebugEvent(this, DebugEvent.CHANGE));
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
@Override
public IStatus validateValue(String value) {
try {
getLong(value);
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
/**
* Returns a float for the string.
*
* @param value string
* @return float
* @throws CoreException if not a valid value
*/
protected long getLong(String value) throws CoreException {
try {
if (value.indexOf(':') == -1) {
long secs = Long.parseLong(value);
return secs * 1000000;
}
} catch (NumberFormatException e) {
throw new CoreException(new Status(IStatus.ERROR, DebugCorePlugin.PLUGIN_ID, "Time must be an integer (seconds) or 00:00 (minutes:seconds) format", e)); //$NON-NLS-1$
}
return 0L;
}
}
|