mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 17:17:29 -05:00
321 - adds a preferred tuner option to the channel's source configuration
so that on startup, the application attempts to source the channel from the preferred tuner. If the tuner is currently not available, or if the tuner cannot source the channel, then the next available tuner is selected.
This commit is contained in:
104
sdr-trunk.ipr
Normal file
104
sdr-trunk.ipr
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<option name="DEFAULT_COMPILER" value="Javac"/>
|
||||||
|
<resourceExtensions>
|
||||||
|
<entry name=".+\.(properties|xml|html|dtd|tld)"/>
|
||||||
|
<entry name=".+\.(gif|png|jpeg|jpg)"/>
|
||||||
|
</resourceExtensions>
|
||||||
|
<wildcardResourcePatterns>
|
||||||
|
<entry name="!?*.class"/>
|
||||||
|
<entry name="!?*.scala"/>
|
||||||
|
<entry name="!?*.java"/>
|
||||||
|
<entry name="!?*.groovy"/>
|
||||||
|
</wildcardResourcePatterns>
|
||||||
|
<annotationProcessing enabled="false" useClasspath="true"/>
|
||||||
|
<bytecodeTargetLevel target="1.8"/>
|
||||||
|
</component>
|
||||||
|
<component name="CopyrightManager" default="">
|
||||||
|
<module2copyright/>
|
||||||
|
</component>
|
||||||
|
<component name="DependencyValidationManager">
|
||||||
|
<option name="SKIP_IMPORT_STATEMENTS" value="false"/>
|
||||||
|
</component>
|
||||||
|
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false"/>
|
||||||
|
<component name="GradleUISettings">
|
||||||
|
<setting name="root"/>
|
||||||
|
</component>
|
||||||
|
<component name="GradleUISettings2">
|
||||||
|
<setting name="root"/>
|
||||||
|
</component>
|
||||||
|
<component name="IdProvider" IDEtalkID="11DA1DB66DD62DDA1ED602B7079FE97C"/>
|
||||||
|
<component name="JavadocGenerationManager">
|
||||||
|
<option name="OUTPUT_DIRECTORY"/>
|
||||||
|
<option name="OPTION_SCOPE" value="protected"/>
|
||||||
|
<option name="OPTION_HIERARCHY" value="true"/>
|
||||||
|
<option name="OPTION_NAVIGATOR" value="true"/>
|
||||||
|
<option name="OPTION_INDEX" value="true"/>
|
||||||
|
<option name="OPTION_SEPARATE_INDEX" value="true"/>
|
||||||
|
<option name="OPTION_DOCUMENT_TAG_USE" value="false"/>
|
||||||
|
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false"/>
|
||||||
|
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false"/>
|
||||||
|
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true"/>
|
||||||
|
<option name="OPTION_DEPRECATED_LIST" value="true"/>
|
||||||
|
<option name="OTHER_OPTIONS" value=""/>
|
||||||
|
<option name="HEAP_SIZE"/>
|
||||||
|
<option name="LOCALE"/>
|
||||||
|
<option name="OPEN_IN_BROWSER" value="true"/>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module filepath="$PROJECT_DIR$/sdr-trunk.iml" fileurl="file://$PROJECT_DIR$/sdr-trunk.iml"/>
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-type="JavaSDK" assert-jdk-15="true" project-jdk-name="1.8">
|
||||||
|
<output url="file://$PROJECT_DIR$/out"/>
|
||||||
|
</component>
|
||||||
|
<component name="SvnBranchConfigurationManager">
|
||||||
|
<option name="mySupportsUserInfoFilter" value="true"/>
|
||||||
|
</component>
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs=""/>
|
||||||
|
</component>
|
||||||
|
<component name="masterDetails">
|
||||||
|
<states>
|
||||||
|
<state key="ArtifactsStructureConfigurable.UI">
|
||||||
|
<UIState>
|
||||||
|
<splitter-proportions>
|
||||||
|
<SplitterProportionsDataImpl/>
|
||||||
|
</splitter-proportions>
|
||||||
|
<settings/>
|
||||||
|
</UIState>
|
||||||
|
</state>
|
||||||
|
<state key="Copyright.UI">
|
||||||
|
<UIState>
|
||||||
|
<splitter-proportions>
|
||||||
|
<SplitterProportionsDataImpl/>
|
||||||
|
</splitter-proportions>
|
||||||
|
</UIState>
|
||||||
|
</state>
|
||||||
|
<state key="ProjectJDKs.UI">
|
||||||
|
<UIState>
|
||||||
|
<splitter-proportions>
|
||||||
|
<SplitterProportionsDataImpl>
|
||||||
|
<option name="proportions">
|
||||||
|
<list>
|
||||||
|
<option value="0.2"/>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</SplitterProportionsDataImpl>
|
||||||
|
</splitter-proportions>
|
||||||
|
<last-edited>1.6</last-edited>
|
||||||
|
</UIState>
|
||||||
|
</state>
|
||||||
|
<state key="ScopeChooserConfigurable.UI">
|
||||||
|
<UIState>
|
||||||
|
<splitter-proportions>
|
||||||
|
<SplitterProportionsDataImpl/>
|
||||||
|
</splitter-proportions>
|
||||||
|
<settings/>
|
||||||
|
</UIState>
|
||||||
|
</state>
|
||||||
|
</states>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -25,7 +25,8 @@ import io.github.dsheirer.source.mixer.MixerSourceEditor;
|
|||||||
import io.github.dsheirer.source.tuner.TunerSourceEditor;
|
import io.github.dsheirer.source.tuner.TunerSourceEditor;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ public class SourceConfigurationEditor extends Editor<Channel>
|
|||||||
mMixerSourceEditor = new MixerSourceEditor( sourceManager );
|
mMixerSourceEditor = new MixerSourceEditor( sourceManager );
|
||||||
mMixerSourceEditor.setSaveRequestListener( this );
|
mMixerSourceEditor.setSaveRequestListener( this );
|
||||||
|
|
||||||
mTunerSourceEditor = new TunerSourceEditor();
|
mTunerSourceEditor = new TunerSourceEditor(sourceManager.getTunerModel());
|
||||||
mTunerSourceEditor.setSaveRequestListener( this );
|
mTunerSourceEditor.setSaveRequestListener( this );
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ public class SourceManager
|
|||||||
return mTunerManager;
|
return mTunerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TunerModel getTunerModel()
|
||||||
|
{
|
||||||
|
return mTunerModel;
|
||||||
|
}
|
||||||
|
|
||||||
public Source getSource(SourceConfiguration config, int bandwidth)
|
public Source getSource(SourceConfiguration config, int bandwidth)
|
||||||
throws SourceException
|
throws SourceException
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,6 +69,15 @@ public class SourceConfigTuner extends SourceConfiguration
|
|||||||
return mPreferredTuner;
|
return mPreferredTuner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if this configuration has a specified preferred tuner
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean hasPreferredTuner()
|
||||||
|
{
|
||||||
|
return mPreferredTuner != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the preferred tuner to use for this configuration
|
* Specifies the preferred tuner to use for this configuration
|
||||||
* @param preferredTuner to use, if available
|
* @param preferredTuner to use, if available
|
||||||
|
|||||||
@@ -70,6 +70,28 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a tuner that matches the name argument
|
||||||
|
*
|
||||||
|
* @param name of the tuner
|
||||||
|
* @return named tuner or null
|
||||||
|
*/
|
||||||
|
public Tuner getTuner(String name)
|
||||||
|
{
|
||||||
|
if(name != null)
|
||||||
|
{
|
||||||
|
for(Tuner tuner: mTuners)
|
||||||
|
{
|
||||||
|
if(tuner.getName().equalsIgnoreCase(name))
|
||||||
|
{
|
||||||
|
return tuner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void addTuners( List<Tuner> Tuners )
|
public void addTuners( List<Tuner> Tuners )
|
||||||
{
|
{
|
||||||
for( Tuner tuner: Tuners )
|
for( Tuner tuner: Tuners )
|
||||||
@@ -271,6 +293,31 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
|
|||||||
|
|
||||||
Tuner tuner;
|
Tuner tuner;
|
||||||
|
|
||||||
|
if(config.hasPreferredTuner())
|
||||||
|
{
|
||||||
|
tuner = getTuner(config.getPreferredTuner());
|
||||||
|
|
||||||
|
if(tuner != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
retVal = tuner.getChannel( tunerChannel );
|
||||||
|
|
||||||
|
if(retVal != null)
|
||||||
|
{
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
//Fall through to logger below
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mLog.info("Unable to source channel [" + config.getFrequency() + "] from preferred tuner [" +
|
||||||
|
config.getPreferredTuner() + "] - searching for another tuner");
|
||||||
|
}
|
||||||
|
|
||||||
while( it.hasNext() && retVal == null )
|
while( it.hasNext() && retVal == null )
|
||||||
{
|
{
|
||||||
tuner = it.next();
|
tuner = it.next();
|
||||||
@@ -285,12 +332,10 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
|
|||||||
}
|
}
|
||||||
catch ( SourceException e )
|
catch ( SourceException e )
|
||||||
{
|
{
|
||||||
mLog.error( "error obtaining channel from tuner [" +
|
mLog.error( "error obtaining channel from tuner [" + tuner.getName() + "]", e );
|
||||||
tuner.getName() + "]", e );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* SDR Trunk
|
||||||
* Copyright (C) 2014 Dennis Sheirer
|
* Copyright (C) 2014-2018 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,70 +26,164 @@ import io.github.dsheirer.source.tuner.frequency.FrequencyChangeEvent;
|
|||||||
import io.github.dsheirer.source.tuner.frequency.IFrequencyChangeProcessor;
|
import io.github.dsheirer.source.tuner.frequency.IFrequencyChangeProcessor;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TunerSourceEditor extends Editor<Channel>
|
public class TunerSourceEditor extends Editor<Channel>
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final String NO_PREFERRED_TUNER = "(none)";
|
||||||
|
private static final String UNAVAILABLE_TUNER = " (unavailable)";
|
||||||
private JFrequencyControl mFrequencyControl;
|
private JFrequencyControl mFrequencyControl;
|
||||||
|
private JComboBox<String> mTunerNameComboBox;
|
||||||
|
private TunerModel mTunerModel;
|
||||||
|
private List<String> mCurrentTunerNames;
|
||||||
|
|
||||||
public TunerSourceEditor()
|
public TunerSourceEditor(TunerModel tunerModel)
|
||||||
{
|
{
|
||||||
init();
|
mTunerModel = tunerModel;
|
||||||
}
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
setLayout( new MigLayout( "insets 0 0 0 0", "[left]", "" ) );
|
loadTunerNames();
|
||||||
mFrequencyControl = new JFrequencyControl();
|
|
||||||
mFrequencyControl.setEnabled( false );
|
|
||||||
mFrequencyControl.addListener( new IFrequencyChangeProcessor()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void frequencyChanged( FrequencyChangeEvent event )
|
|
||||||
{
|
|
||||||
setModified( true );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
add( mFrequencyControl );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save()
|
setLayout(new MigLayout("insets 0 0 0 0", "[left]", ""));
|
||||||
{
|
mFrequencyControl = new JFrequencyControl();
|
||||||
if( hasItem() && isModified() )
|
mFrequencyControl.setEnabled(false);
|
||||||
{
|
mFrequencyControl.addListener(new IFrequencyChangeProcessor()
|
||||||
SourceConfigTuner config = new SourceConfigTuner();
|
{
|
||||||
config.setFrequency( mFrequencyControl.getFrequency() );
|
@Override
|
||||||
getItem().setSourceConfiguration( config );
|
public void frequencyChanged(FrequencyChangeEvent event)
|
||||||
}
|
{
|
||||||
|
setModified(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(mFrequencyControl);
|
||||||
|
|
||||||
setModified( false );
|
mTunerNameComboBox = new JComboBox<>(mCurrentTunerNames.toArray(new String[mCurrentTunerNames.size()]));
|
||||||
}
|
mTunerNameComboBox.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
setModified(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(new JLabel("Preferred Tuner:"));
|
||||||
|
add(mTunerNameComboBox);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private void loadTunerNames()
|
||||||
public void setItem( Channel item )
|
{
|
||||||
{
|
mCurrentTunerNames = new ArrayList<>();
|
||||||
super.setItem( item );
|
|
||||||
|
|
||||||
if( hasItem() )
|
for(Tuner tuner: mTunerModel.getTuners())
|
||||||
{
|
{
|
||||||
SourceConfiguration config = getItem().getSourceConfiguration();
|
mCurrentTunerNames.add(tuner.getName());
|
||||||
|
}
|
||||||
|
|
||||||
mFrequencyControl.setEnabled( true );
|
Collections.sort(mCurrentTunerNames);
|
||||||
|
|
||||||
if( config instanceof SourceConfigTuner )
|
mCurrentTunerNames.add(0, NO_PREFERRED_TUNER);
|
||||||
{
|
}
|
||||||
mFrequencyControl.setFrequency( ((SourceConfigTuner)config).getFrequency(), false );
|
|
||||||
setModified( false );
|
private void updateTunerNameCombo(String preferredTuner)
|
||||||
}
|
{
|
||||||
else
|
if(preferredTuner != null && !mCurrentTunerNames.contains(preferredTuner))
|
||||||
{
|
{
|
||||||
mFrequencyControl.setFrequency( 101000000, false );
|
List<String> updatedTunerNameList = new ArrayList<>(mCurrentTunerNames);
|
||||||
setModified( true );
|
String unavailableTuner = preferredTuner + UNAVAILABLE_TUNER;
|
||||||
}
|
updatedTunerNameList.add(unavailableTuner);
|
||||||
}
|
String[] tunerNameArray = updatedTunerNameList.toArray(new String[updatedTunerNameList.size()]);
|
||||||
else
|
mTunerNameComboBox.setModel(new DefaultComboBoxModel<>(tunerNameArray));
|
||||||
{
|
mTunerNameComboBox.setSelectedItem(unavailableTuner);
|
||||||
mFrequencyControl.setEnabled( false );
|
}
|
||||||
setModified( false );
|
else
|
||||||
}
|
{
|
||||||
}
|
String[] tunerNameArray = mCurrentTunerNames.toArray(new String[mCurrentTunerNames.size()]);
|
||||||
|
mTunerNameComboBox.setModel(new DefaultComboBoxModel<>(tunerNameArray));
|
||||||
|
|
||||||
|
if(preferredTuner == null)
|
||||||
|
{
|
||||||
|
mTunerNameComboBox.setSelectedItem(NO_PREFERRED_TUNER);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mTunerNameComboBox.setSelectedItem(preferredTuner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save()
|
||||||
|
{
|
||||||
|
if(hasItem() && isModified())
|
||||||
|
{
|
||||||
|
SourceConfigTuner config = new SourceConfigTuner();
|
||||||
|
config.setFrequency(mFrequencyControl.getFrequency());
|
||||||
|
|
||||||
|
String preferredTuner = (String)mTunerNameComboBox.getSelectedItem();
|
||||||
|
|
||||||
|
if(preferredTuner != null)
|
||||||
|
{
|
||||||
|
if(preferredTuner.equalsIgnoreCase(NO_PREFERRED_TUNER))
|
||||||
|
{
|
||||||
|
config.setPreferredTuner(null);
|
||||||
|
}
|
||||||
|
else if(preferredTuner.contains(UNAVAILABLE_TUNER))
|
||||||
|
{
|
||||||
|
//don't do anything - the config already contains this unavailable tuner name
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config.setPreferredTuner(preferredTuner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getItem().setSourceConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
setModified(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(Channel item)
|
||||||
|
{
|
||||||
|
super.setItem(item);
|
||||||
|
|
||||||
|
if(hasItem())
|
||||||
|
{
|
||||||
|
SourceConfiguration config = getItem().getSourceConfiguration();
|
||||||
|
|
||||||
|
mFrequencyControl.setEnabled(true);
|
||||||
|
|
||||||
|
if(config instanceof SourceConfigTuner)
|
||||||
|
{
|
||||||
|
SourceConfigTuner tunerConfig = (SourceConfigTuner)config;
|
||||||
|
|
||||||
|
mFrequencyControl.setFrequency(tunerConfig.getFrequency(), false);
|
||||||
|
|
||||||
|
updateTunerNameCombo(tunerConfig.getPreferredTuner());
|
||||||
|
|
||||||
|
setModified(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mFrequencyControl.setFrequency(101000000, false);
|
||||||
|
setModified(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mFrequencyControl.setEnabled(false);
|
||||||
|
setModified(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user