Changeset 572 in josm for trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
- Timestamp:
- 2008-03-02T16:10:33+01:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r567 r572 24 24 import java.net.URLConnection; 25 25 import java.net.UnknownHostException; 26 import java.util.Iterator; 26 27 27 28 import javax.swing.AbstractAction; … … 160 161 }); 161 162 162 JMenuItem applyAudio = new JMenuItem(tr("Make Sampled Audio Layer"), ImageProvider.get("applyaudio"));163 applyAudio.putClientProperty("help", "Action/MakeSampledAudioLayer");164 applyAudio.addActionListener(new ActionListener() {163 JMenuItem importAudio = new JMenuItem(tr("Import Audio"), ImageProvider.get("importaudio")); 164 importAudio.putClientProperty("help", "ImportAudio"); 165 importAudio.addActionListener(new ActionListener() { 165 166 public void actionPerformed(ActionEvent e) { 166 167 String dir = Main.pref.get("markers.lastaudiodirectory"); … … 182 183 if (sel == null) 183 184 return; 184 applyAudio(sel);185 importAudio(sel); 185 186 Main.map.repaint(); 186 187 } … … 245 246 line, 246 247 tagimage, 247 applyAudio,248 importAudio, 248 249 markersFromNamedTrackpoints, 249 250 new JMenuItem(new ConvertToDataLayerAction()), … … 458 459 } 459 460 460 461 461 public class ConvertToDataLayerAction extends AbstractAction { 462 462 public ConvertToDataLayerAction() { … … 485 485 } 486 486 } 487 487 488 488 /** 489 * 490 * 489 * Makes a new marker layer derived from this GpxLayer containing at least one 490 * audio marker which the given audio file is associated with. 491 * Markers are derived from the following 492 * (a) explict waypoints in the GPX layer, or 493 * (b) named trackpoints in the GPX layer, or 494 * (c) (in future) voice recognised markers in the sound recording 495 * (d) a single marker at the beginning of the track 496 * @param wavFile : the file to be associated with the markers in the new marker layer 491 497 */ 492 private void applyAudio(File wavFile) {498 private void importAudio(File wavFile) { 493 499 String uri = "file:".concat(wavFile.getAbsolutePath()); 494 double audioGapSecs = 15.0; 495 try { 496 audioGapSecs = Double.parseDouble(Main.pref.get("marker.audiosampleminsecs", Double.toString(audioGapSecs))); 497 } catch (NumberFormatException e) { 498 } 499 double audioGapMetres = 75.0; 500 try { 501 audioGapMetres = Double.parseDouble(Main.pref.get("marker.audiosampleminmetres", Double.toString(audioGapMetres))); 502 } catch (NumberFormatException e) { 503 } 504 double audioGapRadians = (audioGapMetres / 40041455.0 /* circumference of Earth in metres */) * 2.0 * Math.PI; 505 double audioGapRadiansSquared = audioGapRadians * audioGapRadians; 506 double firstTime = -1.0; 507 double prevOffset = - (audioGapSecs + 1.0); // first point always exceeds time difference 508 WayPoint prevPoint = null; 509 510 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Sampled audio markers from {0}", name), associatedFile, me); 500 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me); 501 502 // (a) try explicit waypoints - unless suppressed 503 if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) && 504 data.waypoints != null && 505 ! data.waypoints.isEmpty()) 506 { 507 double firstTime = -1.0; 508 for (WayPoint w : data.waypoints) { 509 if (firstTime < 0.0) firstTime = w.time; 510 double offset = w.time - firstTime; 511 String name = w.attr.containsKey("name") ? w.getString("name") : 512 w.attr.containsKey("desc") ? w.getString("desc") : 513 AudioMarker.inventName(offset); 514 AudioMarker am = AudioMarker.create(w.latlon, 515 name, uri, ml, w.time, offset); 516 ml.data.add(am); 517 } 518 } 519 520 // (b) use explicitly named track points, again unless suppressed 521 if (ml.data.isEmpty() && 522 Main.pref.getBoolean("marker.namedtrackpoints") && 523 data.tracks != null && 524 ! data.tracks.isEmpty()) 525 { 526 double firstTime = -1.0; 527 for (GpxTrack track : data.tracks) { 528 for (Collection<WayPoint> seg : track.trackSegs) { 529 for (WayPoint w : seg) { 530 String name; 531 if (w.attr.containsKey("name")) 532 name = w.getString("name"); 533 else if (w.attr.containsKey("desc")) 534 name = w.getString("desc"); 535 else 536 continue; 537 if (firstTime < 0.0) firstTime = w.time; 538 double offset = w.time - firstTime; 539 AudioMarker am = AudioMarker.create(w.latlon, 540 name, uri, ml, w.time, offset); 541 ml.data.add(am); 542 } 543 } 544 } 545 } 546 547 // (c) analyse audio for spoken markers here, in due course 511 548 512 for (GpxTrack track : data.tracks) { 513 for (Collection<WayPoint> seg : track.trackSegs) { 514 for (WayPoint point : seg) { 515 double time = point.time; 516 if (firstTime < 0.0) 517 firstTime = time; 518 double offset = time - firstTime; 519 if (prevPoint == null || 520 (offset - prevOffset > audioGapSecs && 521 /* note: distance is misleading: it actually gives distance _squared_ */ 522 point.eastNorth.distance(prevPoint.eastNorth) > audioGapRadiansSquared)) 523 { 524 525 AudioMarker am = AudioMarker.create(point.latlon, 526 AudioMarker.inventName(offset), uri, ml, time, offset); 527 ml.data.add(am); 528 prevPoint = point; 529 prevOffset = offset; 530 } 531 } 532 } 533 } 534 535 if (ml.data.size() > 0) { 549 // (d) simply add a single marker at the start of the track 550 if (ml.data.isEmpty() && 551 data.tracks != null && 552 ! data.tracks.isEmpty()) 553 { 554 for (GpxTrack track : data.tracks) { 555 for (Collection<WayPoint> seg : track.trackSegs) { 556 for (WayPoint w : seg) { 557 AudioMarker am = AudioMarker.create(w.latlon, 558 tr("start"), uri, ml, w.time, 0.0); 559 ml.data.add(am); 560 break; 561 } 562 break; 563 } 564 break; 565 } 566 } 567 568 if (! ml.data.isEmpty()) { 536 569 Main.main.addLayer(ml); 570 } else { 571 JOptionPane.showMessageDialog(Main.parent, tr("Nothing available to associate audio with.")); 537 572 } 538 573 }
Note:
See TracChangeset
for help on using the changeset viewer.
