Changeset 1179 for trunk/src/org/apollo/widgets/SampledTrack.java
- Timestamp:
- 10/02/18 10:18:57 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/widgets/SampledTrack.java
r1156 r1179 159 159 160 160 // Create the immutable mix subject 161 if (mixTemplate == null) 161 if (mixTemplate == null) { 162 162 trackMix = SoundDesk.getInstance().getOrCreateMix(SoundDesk.createPureLocalChannelID(this)); 163 164 else trackMix = SoundDesk.getInstance().createMix( 165 SoundDesk.createPureLocalChannelID(this), 166 mixTemplate.getVolume(), 167 mixTemplate.isMuted()); 163 } else { 164 trackMix = SoundDesk.getInstance().createMix( 165 SoundDesk.createPureLocalChannelID(this), 166 mixTemplate.getVolume(), 167 mixTemplate.isMuted()); 168 } 168 169 169 170 // Keep meta as constant as possible for best results … … 275 276 fulltrackView.addMouseMotionListener(new MouseMotionListener() { 276 277 278 @Override 277 279 public void mouseDragged(MouseEvent e) { 278 280 if (nameLabel != null) { … … 283 285 } 284 286 287 @Override 285 288 public void mouseMoved(MouseEvent e) { 286 289 … … 331 334 fulltrackView.addMouseListener(new MouseListener() { 332 335 336 @Override 333 337 public void mouseClicked(MouseEvent e) { 334 if (trackModel == null) return; 338 if (trackModel == null) { 339 return; 340 } 335 341 336 342 if (nameLabel != null) { … … 349 355 } 350 356 357 @Override 351 358 public void mouseEntered(MouseEvent e) { 352 359 } 353 360 361 @Override 354 362 public void mouseExited(MouseEvent e) { 355 363 } 356 364 365 @Override 357 366 public void mousePressed(MouseEvent e) { 358 367 if (nameLabel != null) { … … 370 379 } 371 380 381 @Override 372 382 public void mouseReleased(MouseEvent e) { 373 383 if (nameLabel != null) { … … 378 388 379 389 if (!e.isConsumed() && e.getButton() == MouseEvent.BUTTON2) { 380 if (split(true)) 390 if (split(true)) { 381 391 e.consume(); 392 } 382 393 } 383 394 … … 393 404 fulltrackView.addKeyListener(new KeyListener() { 394 405 406 @Override 395 407 public void keyPressed(KeyEvent e) 396 408 { 397 409 } 398 410 411 @Override 399 412 public void keyReleased(KeyEvent e) 400 413 { … … 408 421 else if (!e.isControlDown() && e.getKeyCode() == KeyEvent.VK_DELETE) { 409 422 410 if (split(false)) // try Perform delete-split423 if (split(false)) { 411 424 e.consume(); 425 } 412 426 413 427 } … … 420 434 421 435 String name = getName(); 422 if (name == null) name = "Unamed"; 436 if (name == null) { 437 name = "Unamed"; 438 } 423 439 424 440 Mutable.Long initTime = getInitiationTimeFromMeta(); 425 if (initTime == null) initTime = Mutable.createMutableLong(0); 441 if (initTime == null) { 442 initTime = Mutable.createMutableLong(0); 443 } 426 444 427 445 Text linkSource = new Text(current.getNextItemID()); … … 433 451 // Save any changes in the audio - or save for the first time 434 452 if (trackModel.isAudioModified()) 453 { 435 454 saveWidgetData(); // a little lag is OK .. could make smarter if really need to 455 } 436 456 437 457 // Create a new frame to hold the track … … 477 497 } 478 498 499 @Override 479 500 public void keyTyped(KeyEvent e) { 480 501 } … … 486 507 487 508 String metaName = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG); 488 if (metaName == null) metaName = "Untitled"; 509 if (metaName == null) { 510 metaName = "Untitled"; 511 } 489 512 nameLabel.setText(metaName); 490 513 491 514 nameLabel.addTextChangeListener(new TextChangeListener() { // a little bit loopy! 492 515 516 @Override 493 517 public void onTextChanged(Object source, String newLabel) { 494 518 if (trackModel != null && !nameLabel.getText().equals(trackModel.getName())) { … … 558 582 int width = -1; 559 583 if (tl != null) { 560 width = (int)( (double)runningtime / tl.getTimePerPixel());584 width = (int)(runningtime / tl.getTimePerPixel()); 561 585 } 562 586 563 587 // Clamp width to something reasonable. 564 if (width > 0 && width < FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH) width = FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH; 588 if (width > 0 && width < FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH) { 589 width = FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH; 590 } 565 591 566 592 long initTime = (tl == null) ? 0 : tl.getMSTimeAtX(x); … … 573 599 data.add(TrackWidgetCommons.META_INITIATIONTIME_TAG + initTime); 574 600 data.add(TrackWidgetCommons.META_LAST_WIDTH_TAG + width); // although layout manager will handle, just to quick set 575 if (name != null) data.add(TrackWidgetCommons.META_NAME_TAG + name); 601 if (name != null) { 602 data.add(TrackWidgetCommons.META_NAME_TAG + name); 603 } 576 604 577 605 source.setData(data); … … 644 672 data.add(META_LOCALNAME_TAG + localFileName); 645 673 646 if (shouldOmitAudioIndexing) data.add(META_DONT_INDEX_AUDIO_TAG); 674 if (shouldOmitAudioIndexing) { 675 data.add(META_DONT_INDEX_AUDIO_TAG); 676 } 647 677 648 678 String lastName = getName(); 649 679 650 if (lastName != null) 680 if (lastName != null) { 651 681 data.add(TrackWidgetCommons.META_NAME_TAG + lastName); 682 } 652 683 653 684 data.add(TrackWidgetCommons.META_LAST_WIDTH_TAG + getWidth()); … … 663 694 } 664 695 665 if (initTime == null) initTime = getInitiationTimeFromMeta(); // old meta 666 if (initTime == null) initTime = Mutable.createMutableLong(0L); 696 if (initTime == null) 697 { 698 initTime = getInitiationTimeFromMeta(); // old meta 699 } 700 if (initTime == null) { 701 initTime = Mutable.createMutableLong(0L); 702 } 667 703 668 704 data.add(TrackWidgetCommons.META_INITIATIONTIME_TAG + initTime); … … 677 713 public Widget copy() 678 714 throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException { 679 680 715 if (trackModel == null) { 681 716 return super.copy(); 682 717 683 718 } else { 684 685 719 return SampledTrack.createFromMemory( 686 720 trackModel.getAllAudioBytesCopy(), … … 711 745 setLoadScreenMessage("Recovering audio file..."); 712 746 713 if (recoveryFile.exists()) 747 if (recoveryFile.exists()) { 714 748 f = recoveryFile; 749 } 715 750 716 751 } … … 735 770 736 771 // Nullify 737 if (!f.exists() || !f.isFile()) f = null; 772 if (!f.exists() || !f.isFile()) { 773 f = null; 774 } 738 775 739 776 } … … 799 836 // Set the name for this track 800 837 String name = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG); 801 if (name != null) 838 if (name != null) { 802 839 trackModel.setName(name); 840 } 803 841 804 842 initObservers(); // sets default name if non set … … 817 855 SwingUtilities.invokeAndWait(new Runnable() { 818 856 857 @Override 819 858 public void run() { 820 859 … … 859 898 * Used by save manager 860 899 */ 900 @Override 861 901 public boolean doesNeedSaving() { 862 902 return (trackModel != null && (trackModel.isAudioModified() || trackModel.getFilepath() == null)); … … 866 906 * Used by save manager 867 907 */ 908 @Override 868 909 public String getSaveName() { 869 910 870 if (trackModel != null && trackModel.getName() != null) 911 if (trackModel != null && trackModel.getName() != null) { 871 912 return "Sampled Track: " + trackModel.getName(); 872 else return "A Sampled Track"; 913 } else { 914 return "A Sampled Track"; 915 } 873 916 874 917 } … … 890 933 protected void saveWidgetData() { 891 934 892 if (trackModel == null) return; // nothing to save 935 if (trackModel == null) 936 { 937 return; // nothing to save 938 } 893 939 894 940 // If saving for the file time then get a filename … … 920 966 try { 921 967 SwingUtilities.invokeAndWait(new Runnable() { 968 @Override 922 969 public void run() { 923 970 releaseMemory(true); … … 947 994 // Still needs to save? 948 995 if (doesNeedSaving() || trackModel == null) 996 { 949 997 return; // Release memory later when saved 998 } 950 999 951 1000 try { 952 1001 // Release memory - on swing thread to avoid nullified model data wil painting / editing. 953 1002 SwingUtilities.invokeAndWait(new Runnable() { 1003 @Override 954 1004 public void run() { 955 1005 releaseMemory(true); … … 969 1019 970 1020 // Need unloading? 971 if (trackModel == null) return; 1021 if (trackModel == null) { 1022 return; 1023 } 972 1024 973 1025 // Get rid of old temporary files … … 1019 1071 // Release memory - on swing thread to avoid nullified model data wil painting / editing. 1020 1072 SwingUtilities.invokeAndWait(new Runnable() { 1073 @Override 1021 1074 public void run() { 1022 1075 releaseMemory(false); … … 1060 1113 * Global Track model re-use .... 1061 1114 */ 1115 @Override 1062 1116 public SampledTrackModel getSharedSampledTrackModel(String localfilename) { 1063 1117 if (trackModel != null && … … 1109 1163 } 1110 1164 1165 @Override 1111 1166 public void onGraphDirty(SampledTrackGraphView graph, Rectangle dirty) 1112 1167 { … … 1116 1171 } 1117 1172 1173 @Override 1118 1174 public Subject getObservedSubject() { 1119 1175 return null; … … 1132 1188 * Responds to model changed events by updating the GUI ... 1133 1189 */ 1190 @Override 1134 1191 public void modelChanged(Subject source, SubjectChangedEvent event) { 1135 1192 … … 1164 1221 } else { 1165 1222 float perc = ((Float)event.getState()).floatValue(); 1166 if (perc > 1.0f) perc = 1.0f; 1223 if (perc > 1.0f) { 1224 perc = 1.0f; 1225 } 1167 1226 perc *= FILE_LOADING_PERCENT_RANGE; // Dont stretch load to all of bar - still will have more work to do 1168 1227 updateLoadPercentage(perc); … … 1213 1272 1214 1273 Mutable.Long inittime = getInitiationTimeFromMeta(); 1215 if (inittime == null) inittime = Mutable.createMutableLong(0); 1274 if (inittime == null) { 1275 inittime = Mutable.createMutableLong(0); 1276 } 1216 1277 inittime.value += (oldRunningTime - newRunningTime); 1217 1278 … … 1233 1294 } 1234 1295 1296 @Override 1235 1297 public void setObservedSubject(Subject parent) { 1236 1298 } … … 1318 1380 // Draw the name 1319 1381 String name = getName(); 1320 if (name == null) name = "Unnamed"; 1382 if (name == null) { 1383 name = "Unnamed"; 1384 } 1321 1385 1322 1386 g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT)); … … 1419 1483 inferInitTime &= (eventType == ItemParentStateChangedEvent.EVENT_TYPE_ADDED); 1420 1484 1421 if (inferInitTime) 1485 if (inferInitTime) { 1422 1486 initTime = Mutable.createMutableLong(FrameLayoutDaemon.getInstance().getMSAtX(getX(), parent)); 1487 } 1423 1488 } 1424 1489 … … 1549 1614 // Cannot inject into EditableSampledTrackGraphView's while playing, although 1550 1615 // won't break anything, this would be confusing for the user. 1551 if (target.isPlaying()) return; 1616 if (target.isPlaying()) { 1617 return; 1618 } 1552 1619 1553 1620 // Inject the audio at the graph poistion … … 1563 1630 // more references to this item therefore the memory will be freed 1564 1631 // eventually after this invoke 1565 if (destroySelf) removeSelf(); 1632 if (destroySelf) { 1633 removeSelf(); 1634 } 1566 1635 } 1567 1636 … … 1606 1675 * The name given to this widget... can be null. 1607 1676 */ 1677 @Override 1608 1678 public String getName() { 1609 if (this.trackModel != null) 1679 if (this.trackModel != null) { 1610 1680 return trackModel.getName(); 1611 else if (this.nameLabel != null) {1681 } else if (this.nameLabel != null) { 1612 1682 return nameLabel.getText(); 1613 1683 } … … 1624 1694 public Mutable.Long getInitiationTimeFromMeta() { 1625 1695 Long l = getStrippedDataLong(TrackWidgetCommons.META_INITIATIONTIME_TAG, null); 1626 if (l != null) return Mutable.createMutableLong(l.longValue()); 1696 if (l != null) { 1697 return Mutable.createMutableLong(l.longValue()); 1698 } 1627 1699 return null; 1628 1700 } … … 1663 1735 public void setYPosition(int newY) { 1664 1736 1665 if (getY() == newY || isFloating()) return; 1737 if (getY() == newY || isFloating()) { 1738 return; 1739 } 1666 1740 1667 1741 Frame parent = getParentFrame(); 1668 1742 1669 1743 Mutable.Long initTime = getInitiationTimeFromMeta(); 1670 if (initTime == null) return; 1744 if (initTime == null) { 1745 return; 1746 } 1671 1747 1672 1748 setPosition(getX(), newY); … … 1771 1847 // Build the new neighbouring widget 1772 1848 Frame target = getParentFrame(); 1773 if (target == null) target = DisplayController.getCurrentFrame(); 1849 if (target == null) { 1850 target = DisplayController.getCurrentFrame(); 1851 } 1774 1852 1775 1853 // Determine init time 1776 1854 Mutable.Long initTime = getInitiationTimeFromMeta(); 1777 1855 1778 if (initTime == null) initTime = Mutable.createMutableLong(0); 1856 if (initTime == null) { 1857 initTime = Mutable.createMutableLong(0); 1858 } 1779 1859 1780 1860 initTime.value += AudioMath.framesToMilliseconds(rightSideStartFrame, trackModel.getFormat()); … … 1829 1909 Frame parent = getParentFrame(); 1830 1910 String pfname = (parent != null) ? parent.getName() : null; 1831 if (pfname == null) return; 1911 if (pfname == null) { 1912 return; 1913 } 1832 1914 1833 1915 if (!ExpandedTrackManager.getInstance().isTrackInExpansionSelection(trackModel)) { … … 1913 1995 } 1914 1996 1997 @Override 1915 1998 public void actionPerformed(ActionEvent e) { 1916 if (trackModel == null) return; 1999 if (trackModel == null) { 2000 return; 2001 } 1917 2002 1918 2003 if (e.getSource() == playPauseButton) { … … 2012 2097 } 2013 2098 2099 @Override 2014 2100 public Subject getObservedSubject() 2015 2101 { … … 2017 2103 } 2018 2104 2105 @Override 2019 2106 public void setObservedSubject(Subject parent) 2020 2107 { … … 2024 2111 * Receives events from the track model OR from the observed track sequence. 2025 2112 */ 2113 @Override 2026 2114 public void modelChanged(Subject source, SubjectChangedEvent event) 2027 2115 { … … 2109 2197 protected void volumeChanged() 2110 2198 { 2111 trackMix.setVolume(( (float)volumeSlider.getValue()) / 100.0f);2199 trackMix.setVolume((volumeSlider.getValue()) / 100.0f); 2112 2200 } 2113 2201
Note:
See TracChangeset
for help on using the changeset viewer.