Changeset 554 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2008-02-22T18:31:49+01:00 (16 years ago)
Author:
david
Message:

new "Add Audio Marker At Play Head" facility; and tidy up Audio Preferences; default for displaying audio trace now true.

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r553 r554  
    515515                                                point.eastNorth.distance(prevPoint.eastNorth) > audioGapRadiansSquared))
    516516                                        {
    517                                                 String markerName;
    518                                                 int wholeSeconds = (int)(offset + 0.5);
    519                                                 if (wholeSeconds < 60)
    520                                                         markerName = Integer.toString(wholeSeconds);
    521                                                 else if (wholeSeconds < 3600)
    522                                                         markerName = String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
    523                                                 else
    524                                                         markerName = String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
    525                                                 AudioMarker am = AudioMarker.create(point.latlon, markerName, uri, ml, time, offset);
     517                                               
     518                                                AudioMarker am = AudioMarker.create(point.latlon,
     519                                                                AudioMarker.inventName(offset), uri, ml, time, offset);
    526520                                                ml.data.add(am);
    527521                                                prevPoint = point;
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/AudioMarker.java

    r553 r554  
    7575                try {
    7676                        // first enable tracing the audio along the track
    77                         if (Main.pref.getBoolean("marker.traceaudio") && parentLayer != null) {
     77                        if (Main.pref.getBoolean("marker.traceaudio", true) && parentLayer != null) {
    7878                                parentLayer.traceAudio();
    7979                        }
     
    8989                syncOffset = adjustment; // added to offset may turn out negative, but that's ok
    9090        }
     91
     92        public double syncOffset() {
     93                return syncOffset;
     94        }
     95       
     96        public static String inventName (double offset) {
     97                int wholeSeconds = (int)(offset + 0.5);
     98                if (wholeSeconds < 60)
     99                        return Integer.toString(wholeSeconds);
     100                else if (wholeSeconds < 3600)
     101                        return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
     102                else
     103                        return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
     104        }
    91105}
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r553 r554  
    6969        private Rectangle audioTracer = null;
    7070        private Icon audioTracerIcon = null;
    71         private EastNorth audioTracerPosition = null;
     71        private EastNorth playheadPosition = null;
    7272        private static Timer timer = null;
    7373        private static double audioAnimationInterval = 0.0; // seconds
    74         private static double previousTime = -1.0;
     74        private static double playheadTime = -1.0;
    7575
    7676        public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer) {
     
    163163
    164164                if (audioTracer != null) {
    165                         Point screen = Main.map.mapView.getPoint(audioTracerPosition);
     165                        Point screen = Main.map.mapView.getPoint(playheadPosition);
    166166                        audioTracer.setLocation(screen.x, screen.y);
    167167                        audioTracerIcon.paintIcon(Main.map.mapView, g, screen.x, screen.y);
     
    193193                        recentlyPlayedMarker.offset -
    194194                        recentlyPlayedMarker.syncOffset;
    195                 if (Math.abs(audioTime- previousTime) < audioAnimationInterval)
     195                if (Math.abs(audioTime- playheadTime) < audioAnimationInterval)
    196196                        return;
    197197                if (fromLayer == null)
     
    220220                if (w1 == null)
    221221                        return;
    222                 audioTracerPosition = w2 == null ?
     222                playheadPosition = w2 == null ?
    223223                        w1.eastNorth :
    224224                        w1.eastNorth.interpolate(w2.eastNorth,
     
    229229                        audioTracer = new Rectangle(0, 0, audioTracerIcon.getIconWidth(), audioTracerIcon.getIconHeight());                     
    230230                }
    231                 previousTime = audioTime;
     231                playheadTime = audioTime;
    232232                Main.map.mapView.repaint();
    233233        }
     
    322322                });
    323323
    324                 return new Component[] {
    325                         new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    326             new JMenuItem(new LayerListDialog.ShowHideMarkerText(this)),
    327                         new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    328                         new JSeparator(),
    329                         color,
    330                         new JSeparator(),
    331                         syncaudio,
    332                         applyaudio,
    333                         new JMenuItem(new RenameLayerAction(associatedFile, this)),
    334                         new JSeparator(),
    335                         new JMenuItem(new LayerListPopup.InfoAction(this))
    336                 };
     324                JMenuItem moveaudio = new JMenuItem(tr("Make Audio Marker At Play Head"), ImageProvider.get("addmarkers"));
     325                moveaudio.addActionListener(new ActionListener(){
     326                        public void actionPerformed(ActionEvent e) {
     327                                makeAudioMarkerAtPlayHead();
     328                        }
     329                });
     330
     331                Collection<Component> components = new ArrayList<Component>();
     332                components.add(new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)));
     333                components.add(new JMenuItem(new LayerListDialog.ShowHideMarkerText(this)));
     334                components.add(new JMenuItem(new LayerListDialog.DeleteLayerAction(this)));
     335                components.add(new JSeparator());
     336                components.add(color);
     337                components.add(new JSeparator());
     338                components.add(syncaudio);
     339                components.add(applyaudio);
     340                if (Main.pref.getBoolean("marker.traceaudio", true)) {
     341                        components.add (moveaudio);
     342                }               
     343                components.add(new JMenuItem(new RenameLayerAction(associatedFile, this)));
     344                components.add(new JSeparator());
     345                components.add(new JMenuItem(new LayerListPopup.InfoAction(this)));
     346                return components.toArray(new Component[0]);
    337347        }
    338348
    339349        private void adjustOffsetsOnAudioMarkers() {
     350                if (! AudioPlayer.paused()) {
     351                        JOptionPane.showMessageDialog(Main.parent,tr("You need to pause audio at the moment when you hear your synchronization cue."));
     352                        return;
     353                }
    340354                Marker startMarker = AudioMarker.recentlyPlayedMarker();
     355                boolean explicitMarker = true;
    341356                if (startMarker != null && ! data.contains(startMarker)) {
    342                         // message?
     357                        explicitMarker = false;
    343358                        startMarker = null;
    344359                }
     
    354369                if (startMarker == null) {
    355370                        // still no marker to work from - message?
     371                        JOptionPane.showMessageDialog(Main.parent,tr("No audio marker found in the layer to synchronize with."));
    356372                        return;
    357373                }
     
    365381                        if (seenStart) {
    366382                                AudioMarker ma = (AudioMarker) m; // it must be an AudioMarker
    367                                 if (! ma.url().equals(url))
    368                                         break;
    369                                 ma.adjustOffset(adjustment);
    370                         }
    371                 }
     383                                if (ma.url().equals(url))
     384                                        ma.adjustOffset(adjustment);
     385                        }
     386                }
     387               
     388                JOptionPane.showMessageDialog(Main.parent, explicitMarker ?
     389                        tr("Audio synchronized with most recently played marker and subsequent ones (that have the same sound track).") :
     390                        tr("Audio synchronized with audio markers in the layer (that have the same sound track as the first one)."));
     391        }
     392       
     393        private void makeAudioMarkerAtPlayHead() {
     394                if (! AudioPlayer.paused()) {
     395                        JOptionPane.showMessageDialog(Main.parent,tr("You need to pause audio at the point on the track where you want the marker."));
     396                        return;
     397                }
     398                // find first audio marker to get absolute start time
     399                double offset = 0.0;
     400                AudioMarker am = null;
     401                for (Marker m : data) {
     402                        if (m.getClass() == AudioMarker.class) {
     403                                am = (AudioMarker)m;
     404                                offset = playheadTime - am.time;
     405                                break;
     406                        }
     407                }
     408                if (am == null) {
     409                        JOptionPane.showMessageDialog(Main.parent,tr("No existing audio markers in this layer to offset from."));
     410                        return;
     411                }
     412
     413                // make our new marker
     414                AudioMarker newAudioMarker = AudioMarker.create(Main.proj.eastNorth2latlon(playheadPosition),
     415                        AudioMarker.inventName(offset), AudioPlayer.url().toString(), this, playheadTime, offset);
     416               
     417                // insert it at the right place in a copy the collection
     418                Collection<Marker> newData = new ArrayList<Marker>();
     419                am = null;
     420                for (Marker m : data) {
     421                        if (m.getClass() == AudioMarker.class) {
     422                                am = (AudioMarker) m;
     423                                if (newAudioMarker != null && offset < am.offset) {
     424                                        newAudioMarker.adjustOffset(am.syncOffset()); // i.e. same as predecessor
     425                                        newData.add(newAudioMarker);
     426                                        newAudioMarker = null;
     427                                }
     428                        }
     429                        newData.add(m);
     430                }
     431                if (newAudioMarker != null) {
     432                        if (am != null)
     433                                newAudioMarker.adjustOffset(am.syncOffset()); // i.e. same as predecessor                               
     434                        newData.add(newAudioMarker); // insert at end
     435                        newAudioMarker = null;
     436                }
     437               
     438                // replace the collection
     439                data.clear();
     440                data.addAll(newData);
     441                Main.map.mapView.repaint();
    372442        }
    373443       
  • trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java

    r553 r554  
    77import java.awt.event.ActionListener;
    88
     9import javax.swing.Box;
    910import javax.swing.JCheckBox;
    1011import javax.swing.JLabel;
     
    6162                        }
    6263                });
    63                 markerAudioTraceVisible.setSelected(Main.pref.getBoolean("marker.traceaudio"));
     64                markerAudioTraceVisible.setSelected(Main.pref.getBoolean("marker.traceaudio", true));
    6465                markerAudioTraceVisible.setToolTipText(tr("Display a moving icon representing the point on the synchronized track where the audio currently playing was recorded."));
    6566                gui.audio.add(markerAudioTraceVisible, GBC.eol().insets(0,0,0,0));
     
    8586                        }
    8687                });
    87                 markersNamedTrackpoints.setSelected(Main.pref.getBoolean("markers.namedtrackpoints"));
     88                markersNamedTrackpoints.setSelected(Main.pref.getBoolean("marker.namedtrackpoints"));
    8889                markersNamedTrackpoints.setToolTipText(tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions."));
    8990                gui.audio.add(markersNamedTrackpoints, GBC.eol().insets(0,0,0,0));
     
    108109                gui.audio.add(new JLabel(tr("Lead-in time (seconds)")), GBC.std());
    109110                gui.audio.add(audioLeadIn, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     111
     112                gui.audio.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    110113        }
    111114
     
    114117                Main.pref.put("marker.traceaudio", markerAudioTraceVisible.isSelected());
    115118                Main.pref.put("marker.buttonlabels", markerButtonLabels.isSelected());
    116                 Main.pref.put("markers.namedtrackpoints", markersNamedTrackpoints.isSelected());
     119                Main.pref.put("marker.namedtrackpoints", markersNamedTrackpoints.isSelected());
    117120                Main.pref.put("marker.audiosampleminsecs", audioSampleMinSecs.getText());               
    118121                Main.pref.put("marker.audiosampleminmetres", audioSampleMinMetres.getText());           
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r553 r554  
    227227                                break;
    228228                        case wpt:
    229                                 if (qName.equals("ele") || qName.equals("time") || qName.equals("desc")
     229                                if (qName.equals("ele") || qName.equals("desc")
    230230                                                || qName.equals("magvar") || qName.equals("geoidheight")
    231                                                 || qName.equals("name") || qName.equals("time")
    232                                                 || qName.equals("sym") || qName.equals("cmt") || qName.equals("type")) {
     231                                                || qName.equals("name") || qName.equals("sym")
     232                                                || qName.equals("cmt") || qName.equals("type")) {
    233233                                        currentWayPoint.attr.put(qName, accumulator.toString());
     234                                } else if (qName.equals("time")) {
     235                                        currentWayPoint.attr.put(qName, accumulator.toString());
     236                                        currentWayPoint.setTime();                                     
    234237                                } else if (qName.equals("rtept")) {
    235238                                        currentState = states.pop();
    236                                         currentWayPoint.setTime();
    237239                                        currentRoute.routePoints.add(currentWayPoint);
    238240                                } else if (qName.equals("trkpt")) {
    239241                                        currentState = states.pop();
    240                                         currentWayPoint.setTime();
    241242                                        currentTrackSeg.add(currentWayPoint);
    242243                                        if (Main.pref.getBoolean("marker.namedtrackpoints") &&
     
    248249                                } else if (qName.equals("wpt")) {
    249250                                        currentState = states.pop();
    250                                         currentWayPoint.setTime();
    251251                                        currentData.waypoints.add(currentWayPoint);
    252252                                }
Note: See TracChangeset for help on using the changeset viewer.