Skip to content

Commit

Permalink
Merge pull request #256 from DropSnorz/feat/package-formats
Browse files Browse the repository at this point in the history
Multiple formats support in package bundle
  • Loading branch information
DropSnorz authored Aug 20, 2024
2 parents 8aaa434 + a93f3a4 commit a3c6f71
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public Image getPluginFormatIcon(PluginFormat format) {
}
}


/**
* Returns plugin icon based on plugin format.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.owlplug.core.model;

import java.util.Arrays;

public enum PluginFormat {
VST2("VST2"), VST3("VST3"), AU("AU"), LV2("LV2");

Expand All @@ -31,4 +33,23 @@ public String getText() {
return text;
}

/**
* Retrieves an enum instance matching a text string. Returns null if the given
* string doesn't match any defined enum instance.
*
* @param text enum unique text
* @return
*/
public static PluginFormat fromBundleString(String text) {
if (text.equalsIgnoreCase("vst")) {
return PluginFormat.VST2;
}
for (PluginFormat f : PluginFormat.values()) {
if (f.text.equalsIgnoreCase(text)) {
return f;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.owlplug.core.services;

import com.google.common.collect.Iterables;
import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.CoreTaskFactory;
import com.owlplug.core.dao.PluginDAO;
import com.owlplug.core.dao.PluginFootprintDAO;
Expand Down Expand Up @@ -158,6 +159,46 @@ public Iterable<Plugin> findByComponentName(String name, PluginFormat pluginForm
return pluginDAO.findAll(spec);

}

/**
* Get the plugin path based on plugin format.
* @param format plugin format
* @return the directory path
*/
public String getPluginPathByFormat(PluginFormat format) {

if (PluginFormat.VST2.equals(format)) {
return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, "");
} else if (PluginFormat.VST3.equals(format)) {
return this.getPreferences().get(ApplicationDefaults.VST3_DIRECTORY_KEY, "");
} else if (PluginFormat.AU.equals(format)) {
return this.getPreferences().get(ApplicationDefaults.AU_DIRECTORY_KEY, "");
} else if (PluginFormat.LV2.equals(format)) {
return this.getPreferences().get(ApplicationDefaults.LV2_DIRECTORY_KEY, "");
}

return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, "");
}

/**
* Check if format discovery is enabled.
* @param format pluginFormat
* @return true if discovery is enabled.
*/
public boolean isFormatEnabled(PluginFormat format) {

if (PluginFormat.VST2.equals(format)) {
return this.getPreferences().getBoolean(ApplicationDefaults.VST2_DISCOVERY_ENABLED_KEY, false);
} else if (PluginFormat.VST3.equals(format)) {
return this.getPreferences().getBoolean(ApplicationDefaults.VST3_DISCOVERY_ENABLED_KEY, false);
} else if (PluginFormat.AU.equals(format)) {
return this.getPreferences().getBoolean(ApplicationDefaults.AU_DISCOVERY_ENABLED_KEY, false);
} else if (PluginFormat.LV2.equals(format)) {
return this.getPreferences().getBoolean(ApplicationDefaults.LV2_DISCOVERY_ENABLED_KEY, false);
}

return false;
}

/**
* Removes a plugin reference from database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
import com.owlplug.core.components.LazyViewRegistry;
import com.owlplug.core.controllers.BaseController;
import com.owlplug.core.controllers.MainController;
import com.owlplug.core.model.PluginFormat;
import com.owlplug.core.utils.FileUtils;
import com.owlplug.explore.components.ExploreTaskFactory;
import com.owlplug.explore.model.PackageBundle;
import com.owlplug.explore.model.RemotePackage;
import com.owlplug.explore.model.search.ExploreFilterCriteriaType;
import com.owlplug.explore.model.search.StoreFilterCriteria;
import com.owlplug.explore.model.search.ExploreFilterCriteria;
import com.owlplug.explore.services.ExploreService;
import com.owlplug.explore.ui.ExploreChipView;
import com.owlplug.explore.ui.PackageBlocViewBuilder;
Expand Down Expand Up @@ -90,14 +91,14 @@ public class ExploreController extends BaseController {
@FXML
private Button sourcesButton;
@FXML
private Button formatFilterButton;
@FXML
private Button platformFilterButton;
@FXML
private Button syncSourcesButton;
@FXML
private Label resultCounter;
@FXML
private VBox masonryWrapper;
@FXML
private MasonryPane masonryPane;
@FXML
private ScrollPane scrollPane;
Expand All @@ -108,7 +109,9 @@ public class ExploreController extends BaseController {
@FXML
private Pane exploreChipViewContainer;

private HashMap<String, CheckBox> targetFilterCheckBoxes = new HashMap<>();
private final HashMap<String, CheckBox> targetFilterCheckBoxes = new HashMap<>();

private final HashMap<String, CheckBox> formatsFilterCheckBoxes = new HashMap<>();


private ExploreChipView exploreChipView;
Expand Down Expand Up @@ -139,6 +142,31 @@ public void initialize() {
mainController.getLeftDrawer().open();

});

for (PluginFormat format : PluginFormat.values()) {
CheckBox checkbox = new CheckBox(format.getText());
formatsFilterCheckBoxes.put(format.getText().toLowerCase(), checkbox);
checkbox.setSelected(false);
checkbox.setOnAction(e -> {
performPackageSearch();
});
}

VBox formatFilterVbox = new VBox();
formatFilterVbox.setSpacing(5);
formatFilterVbox.setPadding(new Insets(5,10,5,10));
Label formatLabel = new Label("Plugin format");
formatLabel.getStyleClass().add("label-disabled");
formatFilterVbox.getChildren().add(formatLabel);
for (Entry<String, CheckBox> entry : formatsFilterCheckBoxes.entrySet()) {
formatFilterVbox.getChildren().add(entry.getValue());
}

formatFilterButton.setOnAction(e -> {
Popup popup = new Popup(formatFilterVbox);
popup.show(formatFilterButton, Popup.PopupVPosition.TOP, Popup.PopupHPosition.RIGHT);
});


targetFilterCheckBoxes.put("win32", new CheckBox("Windows 32 bits"));
targetFilterCheckBoxes.put("win64", new CheckBox("Windows 64 bits"));
Expand All @@ -152,18 +180,18 @@ public void initialize() {
});
}

VBox vbx = new VBox();
vbx.setSpacing(5);
vbx.setPadding(new Insets(5,10,5,10));
VBox platformFilterVbox = new VBox();
platformFilterVbox.setSpacing(5);
platformFilterVbox.setPadding(new Insets(5,10,5,10));
Label popupLabel = new Label("Target environment contains");
popupLabel.getStyleClass().add("label-disabled");
vbx.getChildren().add(popupLabel);
platformFilterVbox.getChildren().add(popupLabel);
for (Entry<String, CheckBox> entry : targetFilterCheckBoxes.entrySet()) {
vbx.getChildren().add(entry.getValue());
platformFilterVbox.getChildren().add(entry.getValue());
}

platformFilterButton.setOnAction(e -> {
Popup popup = new Popup(vbx);
Popup popup = new Popup(platformFilterVbox);
popup.show(platformFilterButton, Popup.PopupVPosition.TOP, Popup.PopupHPosition.RIGHT);
});

Expand All @@ -176,7 +204,7 @@ public void initialize() {
HBox.setHgrow(exploreChipView, Priority.ALWAYS);
exploreChipViewContainer.getChildren().add(exploreChipView);

exploreChipView.getChips().addListener((ListChangeListener<StoreFilterCriteria>) change -> {
exploreChipView.getChips().addListener((ListChangeListener<ExploreFilterCriteria>) change -> {
performPackageSearch();
});

Expand Down Expand Up @@ -206,14 +234,24 @@ public void changed(ObservableValue<? extends Number> observable, Number oldValu
}

private void performPackageSearch() {
final List<StoreFilterCriteria> criteriaChipList = exploreChipView.getChips();
List<StoreFilterCriteria> criteriaList = new ArrayList<>(criteriaChipList);
final List<ExploreFilterCriteria> criteriaChipList = exploreChipView.getChips();
List<ExploreFilterCriteria> criteriaList = new ArrayList<>(criteriaChipList);

for (Entry<String, CheckBox> entry : targetFilterCheckBoxes.entrySet()) {
if (entry.getValue().isSelected()) {
criteriaList.add(new StoreFilterCriteria(entry.getKey(), ExploreFilterCriteriaType.PLATFORM));
criteriaList.add(new ExploreFilterCriteria(entry.getKey(), ExploreFilterCriteriaType.PLATFORM));
}
}

List<String> formats = new ArrayList<>();
for (Entry<String, CheckBox> entry : formatsFilterCheckBoxes.entrySet()) {
if (entry.getValue().isSelected()) {
formats.add(entry.getKey());
}
}
if (formats.size() > 0) {
criteriaList.add(new ExploreFilterCriteria(formats, ExploreFilterCriteriaType.FORMAT_LIST));
}

Task<Iterable<RemotePackage>> task = new Task<Iterable<RemotePackage>>() {
@Override
Expand Down Expand Up @@ -340,18 +378,22 @@ public boolean installBundle(PackageBundle bundle) {


File selectedDirectory = null;
String baseDirectoryPath = exploreService.getBundleInstallFolder(bundle);
String baseDirectoryPath = null;

// Compute base directory using format if possible
if (exploreService.canDeterminateBundleInstallFolder(bundle)) {
baseDirectoryPath = exploreService.getBundleInstallFolder(bundle);
}

// A custom root directory to store plugin is defined and the base directory for
// the bundle type is defined or not blank.
// the bundle format is defined or not blank.
if (this.getPreferences().getBoolean(ApplicationDefaults.STORE_DIRECTORY_ENABLED_KEY, false) &&
baseDirectoryPath != null && !baseDirectoryPath.isBlank()) {
// Store install target is already defined

String relativeDirectoryPath = this.getPreferences().get(ApplicationDefaults.STORE_DIRECTORY_KEY, "");
Boolean shouldGroupByCreator = this.getPreferences().getBoolean(ApplicationDefaults.STORE_BY_CREATOR_ENABLED_KEY, false);

//if the enduser wishes to group plugins by their creator,
//if the user wishes to group plugins by their creator,
//then we need to include the subdirectory as well.
if (shouldGroupByCreator) {
String creator = FileUtils.sanitizeFileName(bundle.getRemotePackage().getCreator());
Expand All @@ -365,7 +407,9 @@ public boolean installBundle(PackageBundle bundle) {
// Open dialog chooser to define store installation target
DirectoryChooser directoryChooser = new DirectoryChooser();
// Open the VST directory
File initialDirectory = new File(baseDirectoryPath);
String vstDirectory = this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY,
this.getApplicationDefaults().getDefaultPluginPath(PluginFormat.VST2));
File initialDirectory = new File(vstDirectory);
if (initialDirectory.isDirectory()) {
directoryChooser.setInitialDirectory(initialDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void initialize() {
sidebar.collapse();
});

bundlesView = new ProductBundlesView();
bundlesView = new ProductBundlesView(this.getApplicationDefaults());
bundlesContainer.getChildren().add(bundlesView);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package com.owlplug.explore.dao;

import com.owlplug.core.model.PluginType;
import com.owlplug.explore.model.PackageBundle;
import com.owlplug.explore.model.RemotePackage;
import jakarta.persistence.criteria.Fetch;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Predicate;
Expand Down Expand Up @@ -62,23 +64,52 @@ static Specification<RemotePackage> hasCreator(String creator) {


/**
* Platform filtering JPA Specification Filter products matching the given
* platformTag or products without platform assignment.
* Bundle format filtering JPA Specification to filter packages matching the given format.
*
* @param format - The platformTag to find
* @return The JPA Specification
*/
@SuppressWarnings("unchecked")
static Specification<RemotePackage> hasFormat(String format) {
return (remotePackage, cq, cb) -> {
Join<Object, Object> bundles = (Join<Object, Object>) remotePackage.fetch("bundles", JoinType.INNER);
return bundles.join("formats").in(format);
};
}

/**
* Platform filtering JPA Specification Filter packages matching the given
* platformTag or packages without platform assignment.
*
* @param formatList - The compatible platformTagList to find
* @return The JPA Specification
*/
@SuppressWarnings("unchecked")
static Specification<RemotePackage> hasFormat(List<String> formatList) {
return (remotePackage, cq, cb) -> {
Join<Object, Object> bundles = (Join<Object, Object>) remotePackage.fetch("bundles", JoinType.INNER);
return bundles.join("formats").in(formatList);

};
}

/**
* Platform filtering JPA Specification Filter packages matching the given platformTag.
*
* @param platformTag - The platformTag to find
* @return The JPA Specification
*/
@SuppressWarnings("unchecked")
static Specification<RemotePackage> hasPlatformTag(String platformTag) {
return (remotePackage, cq, cb) -> {
Join<Object, Object> bundles = (Join<Object, Object>) remotePackage.fetch("bundles");
return cb.isMember(platformTag, bundles.get("targets"));
Join<Object, Object> bundles = (Join<Object, Object>) remotePackage.fetch("bundles", JoinType.INNER);
return bundles.join("targets").in(platformTag);
};
}

/**
* Platform filtering JPA Specification Filter products matching the given
* platformTag or products without platform assignment.
* Platform filtering JPA Specification Filter packages matching the given
* platformTag or packages without platform assignment.
*
* @param platformTagList - The compatible platformTagList to find
* @return The JPA Specification
Expand All @@ -87,17 +118,13 @@ static Specification<RemotePackage> hasPlatformTag(String platformTag) {
static Specification<RemotePackage> hasPlatformTag(List<String> platformTagList) {
return (remotePackage, cq, cb) -> {
Join<Object, Object> bundles = (Join<Object, Object>) remotePackage.fetch("bundles", JoinType.INNER);
List<Predicate> predicates = new ArrayList<>();
for (String platformTag : platformTagList) {
predicates.add(cb.or(cb.isMember(platformTag, bundles.get("targets"))));
}
cq.distinct(true);
return cb.or(predicates.toArray(new Predicate[predicates.size()]));
return bundles.join("targets").in(platformTagList);

};
}

/**
* Product tag filtering specification. Filter products matching the given tags
* Product tag filtering specification. Filter packages matching the given tags
*
* @param tag - The tag to find
* @return The JPA Specification
Expand All @@ -112,7 +139,7 @@ static Specification<RemotePackage> hasTag(String tag) {
}

/**
* Product tag filtering specification. Filter products matching the given tags
* Product tag filtering specification. Filter packages matching the given tags
*
* @param type - The type to find
* @return The JPA Specification
Expand Down
Loading

0 comments on commit a3c6f71

Please sign in to comment.