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


Ignore:
Timestamp:
2008-03-06T13:50:13+01:00 (16 years ago)
Author:
david
Message:

when dragging play head (a) fix bug re extraneous rubber band rectangle (b) fix small calibration bug, (c) jump to interpolated point on track, not nearest track point.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r526 r577  
    118118        @Override public void exitMode() {
    119119                super.exitMode();
     120                selectionManager.unregister(Main.map.mapView);
    120121                Main.map.mapView.removeMouseListener(this);
    121122                Main.map.mapView.removeMouseMotionListener(this);
     
    210211         */
    211212        @Override public void mousePressed(MouseEvent e) {
     213                if (! (Boolean)this.getValue("active")) return;
    212214                if (e.getButton() != MouseEvent.BUTTON1)
    213215                        return;
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r572 r577  
    5757        private boolean enabled;
    5858        private boolean wasPlaying = false;
     59        private int dropTolerance = 50; /* pixels */
    5960       
    6061        public static PlayHeadMarker create() {
     
    7576                enabled = Main.pref.getBoolean("marker.traceaudio", true);
    7677                if (! enabled) return;
     78                try { dropTolerance = Integer.parseInt(Main.pref.get("marker.playHeadDropTolerance", "50")); }
     79                catch(NumberFormatException x) { dropTolerance = 50; }
    7780                Main.map.mapView.addMouseListener(new MouseAdapter() {
    7881                        @Override public void mousePressed(MouseEvent ev) {
     
    117120         */
    118121        private void endDrag(boolean reset) {
     122                if (! wasPlaying || reset)
     123                        try { AudioPlayer.pause(); }
     124                        catch (Exception ex) { AudioPlayer.audioMalfunction(ex);}
    119125                if (reset)
    120126                        eastNorth = oldEastNorth;
    121127                Main.map.selectMapMode(oldMode);
    122128                Main.map.mapView.repaint();
    123                 if (! wasPlaying)
    124                         try { AudioPlayer.pause(); }
    125                         catch (Exception ex) { AudioPlayer.audioMalfunction(ex);}
    126129                timer.start();
    127130        }
     
    177180         */
    178181        public void reposition(EastNorth en) {
    179                 eastNorth = en;
    180                 WayPoint cw = getClosestTrackPoint(Main.map.mapView.getPoint(en), 25.0);
     182                // eastNorth = en;
     183                WayPoint cw = null;
     184                AudioMarker recent = AudioMarker.recentlyPlayedMarker();
     185                if (recent != null && recent.parentLayer != null && recent.parentLayer.fromLayer != null) {
     186                        /* work out EastNorth equivalent of 50 (default) pixels tolerance */
     187                        Point p = Main.map.mapView.getPoint(en);
     188                        EastNorth enPlus25px = Main.map.mapView.getEastNorth(p.x+dropTolerance, p.y);
     189                        cw = recent.parentLayer.fromLayer.nearestPointOnTrack(en, enPlus25px.east() - en.east());
     190                }
     191               
    181192                AudioMarker ca = null;
    182                
    183193                /* Find the prior audio marker (there should always be one in the
    184194                 * layer, even if it is only one at the start of the track) to
    185195                 * offset the audio from */
    186196                if (cw != null) {
    187                         AudioMarker recent = AudioMarker.recentlyPlayedMarker();               
    188197                        if (recent != null || recent.parentLayer != null) {
    189198                                for (Marker m : recent.parentLayer.data) {
     
    239248                if (ca != null && ! ca.containsPoint(startPoint)) ca = null;
    240249               
    241                 /* If we didn't hit an audio marker, we need to create one at the nearest track point */
    242                 if (ca == null) {
    243                         WayPoint cw = getClosestTrackPoint(startPoint, 10.0);
     250                /* If we didn't hit an audio marker, we need to create one at the nearest point on the track */
     251                if (ca == null && recent != null) {
     252                        /* work out EastNorth equivalent of 50 (default) pixels tolerance */
     253                        Point p = Main.map.mapView.getPoint(en);
     254                        EastNorth enPlus25px = Main.map.mapView.getEastNorth(p.x+dropTolerance, p.y);
     255                        WayPoint cw = recent.parentLayer.fromLayer.nearestPointOnTrack(en, enPlus25px.east() - en.east());
    244256                        if (cw == null) {
    245257                                JOptionPane.showMessageDialog(Main.parent, tr("You need to SHIFT-Drag the play head onto an audio marker or onto the track point where you want to synchronize."));
     
    264276                if (time < 0.0) return;
    265277                Point screen = mv.getPoint(eastNorth);
    266                 // buttonRectangle.setLocation(screen.x+4, screen.y+2);
    267278                symbol.paintIcon(mv, g, screen.x, screen.y);
    268279        }
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r572 r577  
    3737        private double position; // seconds
    3838        private double bytesPerSecond;
    39         private static long chunk = 8000; /* bytes */
     39        private static long chunk = 4000; /* bytes */
    4040        private double speed = 1.0;
    4141
     
    238238                                        break;
    239239                                case PLAYING:
     240                                        command.possiblyInterrupt();
    240241                                        for(;;) {
    241242                                                int nBytesRead = 0;
     
    280281                                                        long nBytesRead = 0;
    281282                                                        position = 0.0;
    282                                                         double adjustedOffset = (offset - leadIn) * calibration;
     283                                                        offset -= leadIn;
     284                                                        double calibratedOffset = offset * calibration;
    283285                                                        bytesPerSecond = audioFormat.getFrameRate() /* frames per second */
    284286                                                                * audioFormat.getFrameSize() /* bytes per frame */;
    285287                                                        if (speed * bytesPerSecond > 256000.0)
    286288                                                                speed = 256000 / bytesPerSecond;
    287                                                         if (offset != 0.0 && adjustedOffset > 0.0) {
     289                                                        if (calibratedOffset > 0.0) {
    288290                                                                long bytesToSkip = (long)(
    289                                                                         adjustedOffset /* seconds (double) */ * bytesPerSecond);
     291                                                                                calibratedOffset /* seconds (double) */ * bytesPerSecond);
    290292                                                                /* skip doesn't seem to want to skip big chunks, so
    291293                                                                 * reduce it to smaller ones
     
    300302                                                                if (bytesToSkip > 0)
    301303                                                                        audioInputStream.skip(bytesToSkip);
    302                                                                 position = adjustedOffset;
     304                                                                position = offset;
    303305                                                        }
    304306                                                        if (audioOutputLine != null)
Note: See TracChangeset for help on using the changeset viewer.