Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit 1a5e8e8

Browse files
committed
Clang format on github run
1 parent 883a138 commit 1a5e8e8

File tree

6 files changed

+172
-99
lines changed

6 files changed

+172
-99
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ SpacesInParentheses: false
5252
SpacesInSquareBrackets: false
5353
TabWidth: 8
5454
UseTab: ForIndentation
55+
---
56+
Language: ObjC

.github/workflows/clang-format.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Clang Format Check
2+
3+
on: [push, pull_request]
4+
jobs:
5+
ubuntu64:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v2
10+
with:
11+
submodules: 'recursive'
12+
13+
- name: Install clang format
14+
run: |
15+
# gets us newer clang
16+
sudo bash -c "cat >> /etc/apt/sources.list" << LLVMAPT
17+
# 3.8
18+
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
19+
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
20+
LLVMAPT
21+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
22+
sudo apt-get -qq update
23+
sudo apt-get install -y clang-format-8
24+
- name: Check the Formatting
25+
run: |
26+
./formatcode.sh
27+
./CI/check-format.sh
28+
macos64:
29+
runs-on: macos-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v2
33+
with:
34+
submodules: 'recursive'
35+
36+
- name: Install clang-format
37+
run: |
38+
brew install clang-format
39+
- name: Check the Formatting
40+
run: |
41+
./formatcode.sh
42+
./CI/check-format.sh

CI/check-format.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
dirty=$(git ls-files --modified)
3+
4+
set +x
5+
if [[ $dirty ]]; then
6+
echo "================================="
7+
echo "Files were not formatted properly"
8+
echo "$dirty"
9+
echo "================================="
10+
exit 1
11+
fi

formatcode.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
# Original source https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/format.sh
3+
4+
set +x
5+
set -o errexit
6+
set -o pipefail
7+
set -o nounset
8+
9+
# Runs the Clang Formatter in parallel on the code base.
10+
# Return codes:
11+
# - 1 there are files to be formatted
12+
# - 0 everything looks fine
13+
14+
# Get CPU count
15+
OS=$(uname)
16+
NPROC=1
17+
if [[ $OS = "Linux" || $OS = "Darwin" ]] ; then
18+
NPROC=$(getconf _NPROCESSORS_ONLN)
19+
fi
20+
21+
# Discover clang-format
22+
if type clang-format-8 2> /dev/null ; then
23+
CLANG_FORMAT=clang-format-8
24+
else
25+
CLANG_FORMAT=clang-format
26+
fi
27+
28+
find . -type d -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
29+
| xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none {}

mac/EditorWidget-osx.mm

+28-31
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,46 @@
2121
#import "../headers/VSTPlugin.h"
2222

2323
void EditorWidget::buildEffectContainer(AEffect *effect) {
24-
cocoaViewContainer = new QMacCocoaViewContainer(nullptr, this);
25-
cocoaViewContainer->move(0, 0);
26-
cocoaViewContainer->resize(300, 300);
27-
NSView *view = [[NSView alloc] initWithFrame: NSMakeRect(0, 0,
28-
300, 300)];
24+
cocoaViewContainer = new QMacCocoaViewContainer(nullptr, this);
25+
cocoaViewContainer->move(0, 0);
26+
cocoaViewContainer->resize(300, 300);
27+
NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300)];
2928

30-
cocoaViewContainer->setCocoaView(view);
29+
cocoaViewContainer->setCocoaView(view);
3130

32-
cocoaViewContainer->show();
31+
cocoaViewContainer->show();
3332

34-
auto *hblParams =new QHBoxLayout();
35-
hblParams->setContentsMargins(0, 0, 0, 0);
36-
hblParams->addWidget(cocoaViewContainer);
33+
auto *hblParams = new QHBoxLayout();
34+
hblParams->setContentsMargins(0, 0, 0, 0);
35+
hblParams->addWidget(cocoaViewContainer);
3736

38-
VstRect* vstRect = nullptr;
39-
effect->dispatcher (effect, effEditGetRect, 0, 0, &vstRect, 0);
40-
if (vstRect)
41-
{
42-
NSRect frame = NSMakeRect(vstRect->left, vstRect->top,
43-
vstRect->right, vstRect->bottom);
37+
VstRect *vstRect = nullptr;
38+
effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0);
39+
if (vstRect) {
40+
NSRect frame = NSMakeRect(vstRect->left, vstRect->top, vstRect->right,
41+
vstRect->bottom);
4442

45-
[view setFrame:frame];
43+
[view setFrame:frame];
4644

47-
cocoaViewContainer->resize(vstRect->right - vstRect->left,
48-
vstRect->bottom- vstRect->top);
45+
cocoaViewContainer->resize(vstRect->right - vstRect->left,
46+
vstRect->bottom - vstRect->top);
4947

50-
this->setGeometry(QRect(0,0,vstRect->right - vstRect->left,
51-
vstRect->bottom- vstRect->top));
52-
}
48+
this->setGeometry(QRect(0, 0, vstRect->right - vstRect->left,
49+
vstRect->bottom - vstRect->top));
50+
}
5351

54-
effect->dispatcher (effect, effEditOpen, 0, 0, view, 0);
52+
effect->dispatcher(effect, effEditOpen, 0, 0, view, 0);
5553

56-
57-
this->setLayout(hblParams);
54+
this->setLayout(hblParams);
5855
}
5956

6057
void EditorWidget::handleResizeRequest(int width, int height) {
61-
resize(width, height);
62-
cocoaViewContainer->resize(width, height);
63-
NSView *view = cocoaViewContainer->cocoaView();
64-
NSRect frame = NSMakeRect(0, 0, width, height);
58+
resize(width, height);
59+
cocoaViewContainer->resize(width, height);
60+
NSView *view = cocoaViewContainer->cocoaView();
61+
NSRect frame = NSMakeRect(0, 0, width, height);
6562

66-
[view setFrame:frame];
63+
[view setFrame:frame];
6764

68-
this->setGeometry(QRect(0,0,width, height));
65+
this->setGeometry(QRect(0, 0, width, height));
6966
}

mac/VSTPlugin-osx.mm

+60-68
Original file line numberDiff line numberDiff line change
@@ -17,75 +17,67 @@
1717

1818
#include "../headers/VSTPlugin.h"
1919

20-
AEffect* VSTPlugin::loadEffect() {
21-
AEffect* newEffect = NULL;
22-
23-
// Create a path to the bundle
24-
CFStringRef pluginPathStringRef = CFStringCreateWithCString(NULL,
25-
pluginPath.c_str(), kCFStringEncodingUTF8);
26-
CFURLRef bundleUrl = CFURLCreateWithFileSystemPath
27-
(kCFAllocatorDefault, pluginPathStringRef,
28-
kCFURLPOSIXPathStyle, true);
29-
30-
if (bundleUrl == NULL)
31-
{
32-
blog(LOG_WARNING, "Couldn't make URL reference for VST plug-in");
33-
return NULL;
34-
}
35-
36-
// Open the bundle
37-
bundle = CFBundleCreate(kCFAllocatorDefault, bundleUrl);
38-
if (bundle == NULL)
39-
{
40-
blog(LOG_WARNING, "Couldn't create VST bundle reference.");
41-
CFRelease(pluginPathStringRef);
42-
CFRelease(bundleUrl);
43-
return NULL;
44-
}
45-
46-
vstPluginMain mainEntryPoint = NULL;
47-
mainEntryPoint = (vstPluginMain) CFBundleGetFunctionPointerForName
48-
(bundle, CFSTR("VSTPluginMain"));
49-
50-
// VST plugins previous to the 2.4 SDK used main_macho for the
51-
// entry point name.
52-
if (mainEntryPoint == NULL)
53-
{
54-
mainEntryPoint = (vstPluginMain)
55-
CFBundleGetFunctionPointerForName(bundle,
56-
CFSTR("main_macho"));
57-
}
58-
59-
if (mainEntryPoint == NULL)
60-
{
61-
blog(LOG_WARNING, "Couldn't get a pointer to plug-in's main()");
62-
CFBundleUnloadExecutable(bundle);
63-
CFRelease(bundle);
64-
return NULL;
65-
}
66-
67-
newEffect = mainEntryPoint(hostCallback_static);
68-
if (newEffect == NULL)
69-
{
70-
blog(LOG_WARNING, "VST Plug-in's main() returns null.");
71-
CFBundleUnloadExecutable(bundle);
72-
CFRelease(bundle);
73-
return NULL;
74-
}
75-
76-
newEffect->user = this;
77-
78-
// Clean up
79-
CFRelease(pluginPathStringRef);
80-
CFRelease(bundleUrl);
81-
82-
return newEffect;
20+
AEffect *VSTPlugin::loadEffect() {
21+
AEffect *newEffect = NULL;
22+
23+
// Create a path to the bundle
24+
CFStringRef pluginPathStringRef = CFStringCreateWithCString(
25+
NULL, pluginPath.c_str(), kCFStringEncodingUTF8);
26+
CFURLRef bundleUrl = CFURLCreateWithFileSystemPath(
27+
kCFAllocatorDefault, pluginPathStringRef, kCFURLPOSIXPathStyle, true);
28+
29+
if (bundleUrl == NULL) {
30+
blog(LOG_WARNING, "Couldn't make URL reference for VST plug-in");
31+
return NULL;
32+
}
33+
34+
// Open the bundle
35+
bundle = CFBundleCreate(kCFAllocatorDefault, bundleUrl);
36+
if (bundle == NULL) {
37+
blog(LOG_WARNING, "Couldn't create VST bundle reference.");
38+
CFRelease(pluginPathStringRef);
39+
CFRelease(bundleUrl);
40+
return NULL;
41+
}
42+
43+
vstPluginMain mainEntryPoint = NULL;
44+
mainEntryPoint = (vstPluginMain)CFBundleGetFunctionPointerForName(
45+
bundle, CFSTR("VSTPluginMain"));
46+
47+
// VST plugins previous to the 2.4 SDK used main_macho for the
48+
// entry point name.
49+
if (mainEntryPoint == NULL) {
50+
mainEntryPoint = (vstPluginMain)CFBundleGetFunctionPointerForName(
51+
bundle, CFSTR("main_macho"));
52+
}
53+
54+
if (mainEntryPoint == NULL) {
55+
blog(LOG_WARNING, "Couldn't get a pointer to plug-in's main()");
56+
CFBundleUnloadExecutable(bundle);
57+
CFRelease(bundle);
58+
return NULL;
59+
}
60+
61+
newEffect = mainEntryPoint(hostCallback_static);
62+
if (newEffect == NULL) {
63+
blog(LOG_WARNING, "VST Plug-in's main() returns null.");
64+
CFBundleUnloadExecutable(bundle);
65+
CFRelease(bundle);
66+
return NULL;
67+
}
68+
69+
newEffect->user = this;
70+
71+
// Clean up
72+
CFRelease(pluginPathStringRef);
73+
CFRelease(bundleUrl);
74+
75+
return newEffect;
8376
}
8477

8578
void VSTPlugin::unloadLibrary() {
86-
if (bundle)
87-
{
88-
CFBundleUnloadExecutable(bundle);
89-
CFRelease(bundle);
90-
}
79+
if (bundle) {
80+
CFBundleUnloadExecutable(bundle);
81+
CFRelease(bundle);
82+
}
9183
}

0 commit comments

Comments
 (0)