Ignore:
Timestamp:
2008-03-02T16:10:33+01:00 (18 years ago)
Author:
david
Message:

Reorganise audio interface in light of recent usability comments

File:
1 edited

Legend:

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

    r567 r572  
    2424import java.net.URLConnection;
    2525import java.net.UnknownHostException;
     26import java.util.Iterator;
    2627
    2728import javax.swing.AbstractAction;
     
    160161                });
    161162
    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() {
    165166                        public void actionPerformed(ActionEvent e) {
    166167                                String dir = Main.pref.get("markers.lastaudiodirectory");
     
    182183                                if (sel == null)
    183184                                        return;
    184                                 applyAudio(sel);
     185                                importAudio(sel);
    185186                                Main.map.repaint();
    186187                        }
     
    245246                                line,
    246247                                tagimage,
    247                                 applyAudio,
     248                                importAudio,
    248249                                markersFromNamedTrackpoints,
    249250                                new JMenuItem(new ConvertToDataLayerAction()),
     
    458459        }
    459460
    460 
    461461        public class ConvertToDataLayerAction extends AbstractAction {
    462462                public ConvertToDataLayerAction() {
     
    485485                }
    486486        }
    487 
     487       
    488488        /**
    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
    491497         */
    492         private void applyAudio(File wavFile) {
     498        private void importAudio(File wavFile) {
    493499                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
    511548           
    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()) {
    536569                Main.main.addLayer(ml);
     570        } else {
     571                        JOptionPane.showMessageDialog(Main.parent, tr("Nothing available to associate audio with."));
    537572        }
    538573        }
Note: See TracChangeset for help on using the changeset viewer.