Skip to content

Commit

Permalink
#466: Many small changes, mainly for status bars
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed Apr 18, 2024
1 parent a7da5d0 commit fcb9d35
Show file tree
Hide file tree
Showing 53 changed files with 480 additions and 144 deletions.
43 changes: 32 additions & 11 deletions src/org/exmaralda/partitureditor/jexmaralda/BasicBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ public BasicBody makeCopy(){
return result;
}

public void smoothTimeline() {
smoothTimeline(0.1);
public int smoothTimeline() {
return smoothTimeline(0.1);
}

public void smoothTimeline(double THRESHHOLD) {
/**
*
* @param THRESHHOLD
* @return
*/
public int smoothTimeline(double THRESHHOLD) {
//double THRESHHOLD = 0.1;
int count=0;
Map<String,String> tliMappings = new HashMap<>();
Timeline tl = getCommonTimeline();
tl.completeTimes();
Expand Down Expand Up @@ -95,7 +101,10 @@ public void smoothTimeline(double THRESHHOLD) {
}
for (String id : tliMappings.keySet()){
tl.removeTimelineItemWithID(id);
count++;
}

return count;
}


Expand Down Expand Up @@ -338,7 +347,9 @@ public String[] makeCanonicalTierOrder(String[] speakerIDs){
return StringUtilities.stringVectorToArray(result);
}

/** reorders the tiers according to the order in the specified array */
/** reorders the tiers according to the order in the specified array
* @param tierIDs
* @throws org.exmaralda.partitureditor.jexmaralda.JexmaraldaException */
public void reorderTiers(String[] tierIDs) throws JexmaraldaException{
BasicBody result = new BasicBody();
result.setCommonTimeline(this.getCommonTimeline());
Expand All @@ -358,7 +369,7 @@ public void reorderTiers(String[] tierIDs) throws JexmaraldaException{
* @return
*/
public String getLastUsedTimelineItem() {
HashSet<String> allEndIDs = new HashSet<String>();
HashSet<String> allEndIDs = new HashSet<>();
for (int pos=0; pos<getNumberOfTiers(); pos++){
Tier tier = getTierAt(pos);
allEndIDs.addAll(Arrays.asList(tier.getAllEndIDs()));
Expand All @@ -374,39 +385,44 @@ public String getLastUsedTimelineItem() {
}

// added 05-11-2009
public void removeUnusedTimelineItems(int selectionStartCol, int selectionEndCol) {
public int removeUnusedTimelineItems(int selectionStartCol, int selectionEndCol) {
int countRemoved = 0;
String[] allIDs = {""};
for (int pos=0; pos<this.getNumberOfTiers(); pos++){
Tier tier = getTierAt(pos);
allIDs = StringUtilities.mergeStringArrays(allIDs, tier.getAllStartIDs());
allIDs = StringUtilities.mergeStringArrays(allIDs, tier.getAllEndIDs());
}
Hashtable usedIDs = new Hashtable();
Map<String, String> usedIDs = new HashMap<>();
for (String allID : allIDs) {
usedIDs.put(allID, "");
}
for (int pos=selectionStartCol; pos<Math.min(selectionEndCol+1, getCommonTimeline().getNumberOfTimelineItems()-1); pos++){
String id = getCommonTimeline().getTimelineItemAt(pos).getID();
if (!usedIDs.containsKey(id)){
getCommonTimeline().removeTimelineItemAt(pos);
countRemoved++;
pos--;
}
}
if (getCommonTimeline().getNumberOfTimelineItems()==0){
getCommonTimeline().addTimelineItem();
}
return countRemoved;
}

/** removes all timeline items that are not the start or end point of
* at least one event */
public void removeUnusedTimelineItems(){
* at least one event
* @return */
public int removeUnusedTimelineItems(){
int countRemoved = 0;
String[] allIDs = {""};
for (int pos=0; pos<this.getNumberOfTiers(); pos++){
Tier tier = getTierAt(pos);
allIDs = StringUtilities.mergeStringArrays(allIDs, tier.getAllStartIDs());
allIDs = StringUtilities.mergeStringArrays(allIDs, tier.getAllEndIDs());
}
Hashtable usedIDs = new Hashtable();
Map<String, String> usedIDs = new HashMap<>();
for (String allID : allIDs) {
usedIDs.put(allID, "");
}
Expand All @@ -417,12 +433,14 @@ public void removeUnusedTimelineItems(){
if (!usedIDs.containsKey(id)){
//System.out.println("Removing tli " + id);
getCommonTimeline().removeTimelineItemAt(pos);
countRemoved++;
pos--;
}
}
if (getCommonTimeline().getNumberOfTimelineItems()==0){
getCommonTimeline().addTimelineItem();
}
return countRemoved;
}

/** returns true if [a) the specified timeline item does not have an absolute time assigned] and
Expand Down Expand Up @@ -460,14 +478,17 @@ public void removeGap(String tli){
}

/** remove all gaps in the transcription */
public void removeAllGaps(){
public int removeAllGaps(){
int count=0;
for (int pos=0; pos<getCommonTimeline().getNumberOfTimelineItems(); pos++){
TimelineItem tli = getCommonTimeline().getTimelineItemAt(pos);
if (isGap(tli.getID())) {
removeGap(tli.getID());
pos--;
count++;
}
}
return count;
}

public boolean areAllEventsOneIntervalLong(Vector eventsThatAreNot){
Expand Down
40 changes: 28 additions & 12 deletions src/org/exmaralda/partitureditor/jexmaralda/Timeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,23 @@ public boolean isConsistent(){
/** kicks out all absolute time values that would make the timeline non-consistent
* returns true if changes to the timeline had to be made, false otherwise
* @return */
public boolean makeConsistent(){
public int makeConsistent(){
int count = 0;
double minTime = 0;
boolean result=false;
for (int pos=0; pos<getNumberOfTimelineItems(); pos++){
double currentTime=getTimelineItemAt(pos).getTime();
if (currentTime>=0){
// changed 28-04-2009: don't allow identical timestamps
// changed again 22-06-2009: don't mistreat the first TLI!
if ((pos>0) && (currentTime<=minTime)) {
getTimelineItemAt(pos).setTime(-0.1);
result=true;
} else {minTime = currentTime;}
count++;
} else {
minTime = currentTime;
}
}
}
return result;
return count;
}

public String[] getInconsistencies(){
Expand Down Expand Up @@ -383,17 +385,19 @@ public void completeTimes(){

/** interpolates the timeline
* @param linear
* @param bt */
public void completeTimes(boolean linear, BasicTranscription bt){
completeTimes(linear, bt, true);
* @param bt
* @return */
public int completeTimes(boolean linear, BasicTranscription bt){
return completeTimes(linear, bt, true);
}
/** interpolates the timeline
* @param linear
* @param bt
* @param reinterpolate */
public void completeTimes(boolean linear, BasicTranscription bt, boolean reinterpolate){
* @param reinterpolate
* @return */
public int completeTimes(boolean linear, BasicTranscription bt, boolean reinterpolate){

if (getNumberOfTimelineItems()==0) {return;}
if (getNumberOfTimelineItems()==0) {return 0;}

// added 12-03-2015: force linear if we do not have tiers of type t
linear = linear || bt.getBody().getTiersOfType("t").length==0;
Expand All @@ -407,6 +411,8 @@ public void completeTimes(boolean linear, BasicTranscription bt, boolean reinter
// Make sure the absolute times are consistent
makeConsistent();


int countChanged = 0;
// Make sure first and last timeline items have absolute time value
TimelineItem tli = getTimelineItemAt(getNumberOfTimelineItems()-1);
if (tli.getTime()<0){
Expand All @@ -420,11 +426,13 @@ public void completeTimes(boolean linear, BasicTranscription bt, boolean reinter
tli.setTime(time);
tli.setType("intp");
}
countChanged++;
}
tli = getTimelineItemAt(0);
if (tli.getTime()<0){
tli.setTime(0);
tli.setType("intp");
countChanged++;
}


Expand All @@ -440,6 +448,7 @@ public void completeTimes(boolean linear, BasicTranscription bt, boolean reinter
TimelineItem tli2 = getTimelineItemAt(lookupID(id2));
tli.setTime(tli1.getTime()+(tli2.getTime()-tli1.getTime())/(lookupID(id2)-lookupID(id1)));
tli.setType("intp");
countChanged++;
}
}
} else {
Expand Down Expand Up @@ -497,6 +506,8 @@ public void completeTimes(boolean linear, BasicTranscription bt, boolean reinter
double time = tli1.getTime()+(tli2.getTime()-tli1.getTime())*proportion;
tli.setTime(time);
tli.setType("intp");
countChanged++;

}

//System.out.println("=================");
Expand All @@ -505,17 +516,22 @@ public void completeTimes(boolean linear, BasicTranscription bt, boolean reinter
}
}
}

return countChanged;
}


/** remove absolute times that have been interpolated */
public void removeInterpolatedTimes(){
public int removeInterpolatedTimes(){
int count=0;
for (int pos=0; pos<getNumberOfTimelineItems(); pos++){
TimelineItem tli = getTimelineItemAt(pos);
if ((tli.getTime()>=0) && (tli.getType().equals("intp"))){
tli.setTime(-1);
count++;
}
}
return count;
}

public void removeTimes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
Expand Down Expand Up @@ -49,7 +50,7 @@
<SubComponents>
<Component class="javax.swing.JButton" name="gotoButton">
<Properties>
<Property name="text" type="java.lang.String" value="Go to..."/>
<Property name="text" type="java.lang.String" value="Go to selected bookmark"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="gotoButtonActionPerformed"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BookmarksDialog(java.awt.Frame parent, boolean modal, Timeline tl) {
super(parent, modal);
timeline = tl;
initComponents();
allBookmarks = tl.getAllBookmarks();
allBookmarks = timeline.getAllBookmarks();
for (int pos=0; pos<allBookmarks.size(); pos++){
TimelineItem tli = (TimelineItem)(allBookmarks.elementAt(pos));
bookmarksListModel.addElement(tli.getBookmark());
Expand Down Expand Up @@ -71,7 +71,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {

getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

gotoButton.setText("Go to...");
gotoButton.setText("Go to selected bookmark");
gotoButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gotoButtonActionPerformed(evt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<SubComponents>
<Component class="javax.swing.JButton" name="upButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/org/exmaralda/folker/tangoicons/tango-icon-theme-0.8.1/16x16/actions/go-up.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Up"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[107, 27]"/>
Expand All @@ -81,6 +84,9 @@
</Component>
<Component class="javax.swing.JButton" name="downButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/org/exmaralda/folker/tangoicons/tango-icon-theme-0.8.1/16x16/actions/go-down.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Down"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[107, 27]"/>
Expand Down
Loading

0 comments on commit fcb9d35

Please sign in to comment.